from datetime import datetime, timezone
from typing import Dict, List, Optional, Tuple
from uuid import UUID

from fastapi import HTTPException, status
from sqlalchemy import and_, func, or_
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session, aliased
from sqlalchemy.sql.expression import nullslast

from src.apps.wine.bottle_size.models.bottle_size import BottleSize
from src.core.config import settings
from src.core.exceptions import APIException
from src.utils.constants import API_PREFIXES
from src.utils.pagination import QueryPaginator


async def get_bottle_size_map(db: Session) -> Dict[str, BottleSize]:
    """
    Asynchronously creates a map of bottle size IDs to BottleSize objects.

    Args:
        session (Session): SQLAlchemy session for database interaction.

    Returns:
        Dict[str, BottleSize]: A dictionary mapping bottle size IDs to BottleSize objects.
    """
    bottle_size_map = {}

    # Query all BottleSize objects from the database
    bottle_sizes = db.query(BottleSize).filter(BottleSize.deleted_at.is_(None)).all()

    for bottle_size in bottle_sizes:
        bottle_size_map[bottle_size.id] = bottle_size

    return bottle_size_map

