"""Kitchen repositories — Phase 12.6."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy import select

from app.models.kitchen import KitchenStation, KitchenTicket, KitchenTicketItem
from app.repositories.base import TenantBaseRepository


class KitchenStationRepository(TenantBaseRepository[KitchenStation]):
    model = KitchenStation

    async def get_by_code(
        self, tenant_id: UUID, venue_id: UUID, code: str
    ) -> KitchenStation | None:
        stmt = select(KitchenStation).where(
            KitchenStation.tenant_id == tenant_id,
            KitchenStation.venue_id == venue_id,
            KitchenStation.code == code,
            KitchenStation.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()


class KitchenTicketRepository(TenantBaseRepository[KitchenTicket]):
    model = KitchenTicket

    async def get_by_code(
        self, tenant_id: UUID, venue_id: UUID, code: str
    ) -> KitchenTicket | None:
        stmt = select(KitchenTicket).where(
            KitchenTicket.tenant_id == tenant_id,
            KitchenTicket.venue_id == venue_id,
            KitchenTicket.code == code,
            KitchenTicket.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()


class KitchenTicketItemRepository(TenantBaseRepository[KitchenTicketItem]):
    model = KitchenTicketItem
