from app_resources import AppResources
from ports.client_repository import ClientRepository
from ports.salon_repository import SalonRepository


class EnrichCallContextUseCase:
    def __init__(
        self,
        client_repository: ClientRepository,
        salon_repository: SalonRepository,
    ):
        self._clients = client_repository
        self._salons = salon_repository

    async def execute(
        self, resources: AppResources, to_number: str | None
    ) -> AppResources:
        timezone = await self._salons.get_timezone(resources.salon_id)
        client_id = resources.client_id
        if to_number and not client_id:
            client_id = await self._clients.resolve_or_create(
                resources.salon_id, to_number
            )
        return AppResources(
            salon_id=resources.salon_id,
            client_id=client_id,
            timezone=timezone,
        )
