"""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.salon import TreatmentRoom
from app.repositories.base import TenantBaseRepository


class TreatmentRoomRepository(TenantBaseRepository[TreatmentRoom]):
    model = TreatmentRoom

    async def get_by_code(self, tenant_id: UUID, code: str) -> TreatmentRoom | 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.salon import Station
from app.repositories.base import TenantBaseRepository


class StationRepository(TenantBaseRepository[Station]):
    model = Station

    async def get_by_code(self, tenant_id: UUID, code: str) -> Station | 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.salon import BranchPolicy
from app.repositories.base import TenantBaseRepository


class BranchPolicyRepository(TenantBaseRepository[BranchPolicy]):
    model = BranchPolicy

    async def get_by_code(self, tenant_id: UUID, code: str) -> BranchPolicy | 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()
