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


class CustomerProfileRepository(TenantBaseRepository[CustomerProfile]):
    model = CustomerProfile

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