from __future__ import annotations

from app.repositories.directus.marketing_cards import MarketingCardRepository
from app.schemas.marketing_card import MarketingCardRead


class MarketingCardService:
    """Application service for the current marketing-card module.

    This keeps the legacy module reachable while frontend migration is in
    progress. Later we can either map it into experiment/variant concepts or
    retire it after the new module replaces it.
    """

    def __init__(self, repository: MarketingCardRepository | None = None) -> None:
        self.repository = repository or MarketingCardRepository()

    async def list_marketing_cards(self) -> list[MarketingCardRead]:
        items = await self.repository.list()
        return [MarketingCardRead.model_validate(item) for item in items]

    async def get_marketing_card(self, card_id: str) -> MarketingCardRead | None:
        item = await self.repository.get(card_id)
        if not item:
            return None
        return MarketingCardRead.model_validate(item)

