from aquacrop.file_generators.DATA.cal_generator import generate_calendar_file


class Calendar:
    """
    Represents crop calendar parameters for AquaCrop simulation
    """

    def __init__(
        self,
        name: str,
        description: str,
        onset_mode: int = 0,
        day_number: int = 1,
        window_start_day: int = 1,
        window_length: int = 90,
        criterion_number: int = 1,
        criterion_value: float = 20.0,
        successive_days: int = 1,
        occurrences: int = 1,
    ):
        """
        Initialize a calendar entity

        Args:
            name: Calendar name (used for file naming)
            description: Calendar description
            onset_mode: Calendar mode (0=fixed date, 1=generated by a rainfall or air temperature criterion)
            day_number: Day number (1-366) for onset of growing period (mode 0)
            window_start_day: Day-number (1-365) of start of time window (mode 1)
            window_length: Length (days) of the time window (mode 1)
            criterion_number: Criterion number for generation of onset (mode 1)
            criterion_value: Value for the specified criterion (mode 1)
            successive_days: Number of successive days for criterion (mode 1)
            occurrences: Number of occurrences before criterion applies (mode 1)
        """
        self.name = "".join(name.split())
        self.description = description
        self.onset_mode = onset_mode
        self.day_number = day_number
        self.window_start_day = window_start_day
        self.window_length = window_length
        self.criterion_number = criterion_number
        self.criterion_value = criterion_value
        self.successive_days = successive_days
        self.occurrences = occurrences

    def generate_file(self, directory: str) -> str:
        """Generate calendar file in directory and return file path"""
        return generate_calendar_file(
            file_path=f"{directory}/{self.name}.CAL",
            description=self.description,
            onset_mode=self.onset_mode,
            day_number=self.day_number,
            window_start_day=self.window_start_day,
            window_length=self.window_length,
            criterion_number=self.criterion_number,
            criterion_value=self.criterion_value,
            successive_days=self.successive_days,
            occurrences=self.occurrences,
        )
