from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.script_schedule_days_item import ScriptScheduleDaysItem
from ..types import UNSET, Unset

T = TypeVar("T", bound="ScriptSchedule")


@_attrs_define
class ScriptSchedule:
    """
    Attributes:
        weekly (bool | Unset):
        dates (list[float] | Unset):
        days (list[ScriptScheduleDaysItem] | Unset):
        hours (list[float] | Unset):
    """

    weekly: bool | Unset = UNSET
    dates: list[float] | Unset = UNSET
    days: list[ScriptScheduleDaysItem] | Unset = UNSET
    hours: list[float] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        weekly = self.weekly

        dates: list[float] | Unset = UNSET
        if not isinstance(self.dates, Unset):
            dates = self.dates

        days: list[str] | Unset = UNSET
        if not isinstance(self.days, Unset):
            days = []
            for days_item_data in self.days:
                days_item = days_item_data.value
                days.append(days_item)

        hours: list[float] | Unset = UNSET
        if not isinstance(self.hours, Unset):
            hours = self.hours

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if weekly is not UNSET:
            field_dict["weekly"] = weekly
        if dates is not UNSET:
            field_dict["dates"] = dates
        if days is not UNSET:
            field_dict["days"] = days
        if hours is not UNSET:
            field_dict["hours"] = hours

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        weekly = d.pop("weekly", UNSET)

        dates = cast(list[float], d.pop("dates", UNSET))

        _days = d.pop("days", UNSET)
        days: list[ScriptScheduleDaysItem] | Unset = UNSET
        if _days is not UNSET:
            days = []
            for days_item_data in _days:
                days_item = ScriptScheduleDaysItem(days_item_data)

                days.append(days_item)

        hours = cast(list[float], d.pop("hours", UNSET))

        script_schedule = cls(
            weekly=weekly,
            dates=dates,
            days=days,
            hours=hours,
        )

        script_schedule.additional_properties = d
        return script_schedule

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
