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


class MarketingCampaignRefRepository(TenantBaseRepository[MarketingCampaignRef]):
    model = MarketingCampaignRef

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


class LoyaltyIntegrationConfigRepository(TenantBaseRepository[LoyaltyIntegrationConfig]):
    model = LoyaltyIntegrationConfig

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


class CommunicationIntegrationConfigRepository(TenantBaseRepository[CommunicationIntegrationConfig]):
    model = CommunicationIntegrationConfig

    async def get_by_code(self, tenant_id: UUID, code: str) -> CommunicationIntegrationConfig | 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 app.models.marketing import IntegrationDispatch


class IntegrationDispatchRepository(TenantBaseRepository[IntegrationDispatch]):
    model = IntegrationDispatch
