"""The public menu."""
from typing import Annotated

from fastapi import APIRouter, Depends, Response
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

from ..db import get_session
from ..models import Product
from ..schemas import ProductOut

router = APIRouter(prefix="/v1/products", tags=["products"])


@router.get("")
async def list_products(response: Response,
                        session: Annotated[AsyncSession, Depends(get_session)]) -> list[ProductOut]:
    response.headers["Cache-Control"] = "public, max-age=60"       # safe: no per-user data
    return list(await session.scalars(select(Product).where(Product.active).order_by(Product.id)))
