"""Holiday CRUD use cases (admin only, enforced at the interfaces layer)."""
from __future__ import annotations

import datetime

from domain.exceptions import HolidayAlreadyExistsError
from domain.repositories import HolidayRepository


class CreateHoliday:
    def __init__(self, holiday_repo: HolidayRepository):
        self.holiday_repo = holiday_repo

    def execute(self, date: datetime.date, title: str, description: str | None = None):
        if self.holiday_repo.exists_on_date(date):
            raise HolidayAlreadyExistsError(f"A holiday already exists on {date}.")
        return self.holiday_repo.create(date=date, title=title, description=description)


class DeleteHoliday:
    def __init__(self, holiday_repo: HolidayRepository):
        self.holiday_repo = holiday_repo

    def execute(self, holiday_id: int) -> None:
        self.holiday_repo.delete(holiday_id)
