"""Repositories."""
from __future__ import annotations
from uuid import UUID
from sqlalchemy import select
from app.repositories.base import TenantBaseRepository


from uuid import UUID

from sqlalchemy import select

from app.models.appointments import StaffSchedule
from app.repositories.base import TenantBaseRepository


class StaffScheduleRepository(TenantBaseRepository[StaffSchedule]):
    model = StaffSchedule

    async def get_by_code(self, tenant_id: UUID, code: str) -> StaffSchedule | None:
        if not hasattr(self.model, "code"):
            return None
        stmt = select(self.model).where(
            self.model.tenant_id == tenant_id,
            self.model.code == code,
            self.model.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()


from uuid import UUID

from sqlalchemy import select

from app.models.appointments import StaffAvailability
from app.repositories.base import TenantBaseRepository


class StaffAvailabilityRepository(TenantBaseRepository[StaffAvailability]):
    model = StaffAvailability

    async def get_by_code(self, tenant_id: UUID, code: str) -> StaffAvailability | None:
        if not hasattr(self.model, "code"):
            return None
        stmt = select(self.model).where(
            self.model.tenant_id == tenant_id,
            self.model.code == code,
            self.model.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()


from uuid import UUID

from sqlalchemy import select

from app.models.appointments import ScheduleException
from app.repositories.base import TenantBaseRepository


class ScheduleExceptionRepository(TenantBaseRepository[ScheduleException]):
    model = ScheduleException

    async def get_by_code(self, tenant_id: UUID, code: str) -> ScheduleException | None:
        if not hasattr(self.model, "code"):
            return None
        stmt = select(self.model).where(
            self.model.tenant_id == tenant_id,
            self.model.code == code,
            self.model.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()


from uuid import UUID

from sqlalchemy import select

from app.models.appointments import AppointmentType
from app.repositories.base import TenantBaseRepository


class AppointmentTypeRepository(TenantBaseRepository[AppointmentType]):
    model = AppointmentType

    async def get_by_code(self, tenant_id: UUID, code: str) -> AppointmentType | None:
        if not hasattr(self.model, "code"):
            return None
        stmt = select(self.model).where(
            self.model.tenant_id == tenant_id,
            self.model.code == code,
            self.model.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()


from uuid import UUID

from sqlalchemy import select

from app.models.appointments import WaitingListEntry
from app.repositories.base import TenantBaseRepository


class WaitingListEntryRepository(TenantBaseRepository[WaitingListEntry]):
    model = WaitingListEntry

    async def get_by_code(self, tenant_id: UUID, code: str) -> WaitingListEntry | None:
        if not hasattr(self.model, "code"):
            return None
        stmt = select(self.model).where(
            self.model.tenant_id == tenant_id,
            self.model.code == code,
            self.model.is_deleted.is_(False),
        )
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()
