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


class StaffProfileRepository(TenantBaseRepository[StaffProfile]):
    model = StaffProfile

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


class CommissionRuleRepository(TenantBaseRepository[CommissionRule]):
    model = CommissionRule

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