from __future__ import annotations

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

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

from ..models.e_day_of_week import EDayOfWeek
from ..models.e_script_periodicity_type import EScriptPeriodicityType
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.script_command import ScriptCommand


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


@_attrs_define
class JobScriptsSettingsModel:
    """Script settings.<ul><li>`preCommand` — script executed before the job</li><li>`postCommand` — script executed after
    the job</li></ul>

        Attributes:
            pre_command (ScriptCommand | Unset): Script settings.
            post_command (ScriptCommand | Unset): Script settings.
            periodicity_type (EScriptPeriodicityType | Unset): Type of script periodicity.
            run_script_every (int | Unset): Number of the backup job session after which the scripts must be executed.
            day_of_week (list[EDayOfWeek] | Unset): Days of the week when the scripts must be executed.
    """

    pre_command: ScriptCommand | Unset = UNSET
    post_command: ScriptCommand | Unset = UNSET
    periodicity_type: EScriptPeriodicityType | Unset = UNSET
    run_script_every: int | Unset = UNSET
    day_of_week: list[EDayOfWeek] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        pre_command: dict[str, Any] | Unset = UNSET
        if not isinstance(self.pre_command, Unset):
            pre_command = self.pre_command.to_dict()

        post_command: dict[str, Any] | Unset = UNSET
        if not isinstance(self.post_command, Unset):
            post_command = self.post_command.to_dict()

        periodicity_type: str | Unset = UNSET
        if not isinstance(self.periodicity_type, Unset):
            periodicity_type = self.periodicity_type.value

        run_script_every = self.run_script_every

        day_of_week: list[str] | Unset = UNSET
        if not isinstance(self.day_of_week, Unset):
            day_of_week = []
            for day_of_week_item_data in self.day_of_week:
                day_of_week_item = day_of_week_item_data.value
                day_of_week.append(day_of_week_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if pre_command is not UNSET:
            field_dict["preCommand"] = pre_command
        if post_command is not UNSET:
            field_dict["postCommand"] = post_command
        if periodicity_type is not UNSET:
            field_dict["periodicityType"] = periodicity_type
        if run_script_every is not UNSET:
            field_dict["runScriptEvery"] = run_script_every
        if day_of_week is not UNSET:
            field_dict["dayOfWeek"] = day_of_week

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.script_command import ScriptCommand

        d = dict(src_dict)
        _pre_command = d.pop("preCommand", UNSET)
        pre_command: ScriptCommand | Unset
        if isinstance(_pre_command, Unset):
            pre_command = UNSET
        else:
            pre_command = ScriptCommand.from_dict(_pre_command)

        _post_command = d.pop("postCommand", UNSET)
        post_command: ScriptCommand | Unset
        if isinstance(_post_command, Unset):
            post_command = UNSET
        else:
            post_command = ScriptCommand.from_dict(_post_command)

        _periodicity_type = d.pop("periodicityType", UNSET)
        periodicity_type: EScriptPeriodicityType | Unset
        if isinstance(_periodicity_type, Unset):
            periodicity_type = UNSET
        else:
            periodicity_type = EScriptPeriodicityType(_periodicity_type)

        run_script_every = d.pop("runScriptEvery", UNSET)

        _day_of_week = d.pop("dayOfWeek", UNSET)
        day_of_week: list[EDayOfWeek] | Unset = UNSET
        if _day_of_week is not UNSET:
            day_of_week = []
            for day_of_week_item_data in _day_of_week:
                day_of_week_item = EDayOfWeek(day_of_week_item_data)

                day_of_week.append(day_of_week_item)

        job_scripts_settings_model = cls(
            pre_command=pre_command,
            post_command=post_command,
            periodicity_type=periodicity_type,
            run_script_every=run_script_every,
            day_of_week=day_of_week,
        )

        job_scripts_settings_model.additional_properties = d
        return job_scripts_settings_model

    @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
