from ports.service_repository import ServiceRepository


class GetServiceCatalogUseCase:
    EMPTY_MESSAGE = "Sorry, there are no services available at the moment."
    PREFIX = "Here are the available services. "
    MAX_SERVICES = 7

    def __init__(self, repository: ServiceRepository):
        self._repository = repository

    async def execute(self, salon_id: str) -> str:
        services = await self._repository.list_available_services(salon_id)
        if not services:
            return self.EMPTY_MESSAGE

        ordered = sorted(services, key=lambda service: service.name.lower())
        parts = [
            (
                f"{service.name}, "
                f"{service.duration if service.duration is not None else 'N/A'} minutes, "
                f"€{service.price if service.price is not None else 'N/A'}"
            )
            for service in ordered[: self.MAX_SERVICES]
        ]
        return self.PREFIX + ". ".join(parts)
