from __future__ import annotations

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

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_clients_filter import TypesClientsFilter
    from ..models.types_deals_filter import TypesDealsFilter
    from ..models.types_field import TypesField
    from ..models.types_plans_filter import TypesPlansFilter


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


@_attrs_define
class TypesProjectSchedule:
    """
    Attributes:
        clients (list[str] | Unset):
        clients_filter (TypesClientsFilter | Unset):
        deals (list[str] | Unset):
        deals_filter (TypesDealsFilter | Unset):
        due (str | Unset): Due - can either be a specific date or relative to the project launch date
        fields (list[TypesField] | Unset): Fields to be set to the project
        file (str | Unset): Who are we launching it for? (clients/plans)
        frequency (str | Unset):
        ignore_active (bool | Unset): Ignore resource who already have active projects with this template?
        lead (str | Unset):
        plans (list[str] | Unset):
        plans_filter (TypesPlansFilter | Unset):
        timestamp (str | Unset): Schedules
            When are we launching it?
    """

    clients: list[str] | Unset = UNSET
    clients_filter: TypesClientsFilter | Unset = UNSET
    deals: list[str] | Unset = UNSET
    deals_filter: TypesDealsFilter | Unset = UNSET
    due: str | Unset = UNSET
    fields: list[TypesField] | Unset = UNSET
    file: str | Unset = UNSET
    frequency: str | Unset = UNSET
    ignore_active: bool | Unset = UNSET
    lead: str | Unset = UNSET
    plans: list[str] | Unset = UNSET
    plans_filter: TypesPlansFilter | Unset = UNSET
    timestamp: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

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

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

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

        due = self.due

        fields: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.fields, Unset):
            fields = []
            for fields_item_data in self.fields:
                fields_item = fields_item_data.to_dict()
                fields.append(fields_item)

        file = self.file

        frequency = self.frequency

        ignore_active = self.ignore_active

        lead = self.lead

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

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

        timestamp = self.timestamp

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if clients is not UNSET:
            field_dict["clients"] = clients
        if clients_filter is not UNSET:
            field_dict["clients_filter"] = clients_filter
        if deals is not UNSET:
            field_dict["deals"] = deals
        if deals_filter is not UNSET:
            field_dict["deals_filter"] = deals_filter
        if due is not UNSET:
            field_dict["due"] = due
        if fields is not UNSET:
            field_dict["fields"] = fields
        if file is not UNSET:
            field_dict["file"] = file
        if frequency is not UNSET:
            field_dict["frequency"] = frequency
        if ignore_active is not UNSET:
            field_dict["ignore_active"] = ignore_active
        if lead is not UNSET:
            field_dict["lead"] = lead
        if plans is not UNSET:
            field_dict["plans"] = plans
        if plans_filter is not UNSET:
            field_dict["plans_filter"] = plans_filter
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_clients_filter import TypesClientsFilter
        from ..models.types_deals_filter import TypesDealsFilter
        from ..models.types_field import TypesField
        from ..models.types_plans_filter import TypesPlansFilter

        d = dict(src_dict)
        clients = cast(list[str], d.pop("clients", UNSET))

        _clients_filter = d.pop("clients_filter", UNSET)
        clients_filter: TypesClientsFilter | Unset
        if isinstance(_clients_filter, Unset):
            clients_filter = UNSET
        else:
            clients_filter = TypesClientsFilter.from_dict(_clients_filter)

        deals = cast(list[str], d.pop("deals", UNSET))

        _deals_filter = d.pop("deals_filter", UNSET)
        deals_filter: TypesDealsFilter | Unset
        if isinstance(_deals_filter, Unset):
            deals_filter = UNSET
        else:
            deals_filter = TypesDealsFilter.from_dict(_deals_filter)

        due = d.pop("due", UNSET)

        _fields = d.pop("fields", UNSET)
        fields: list[TypesField] | Unset = UNSET
        if _fields is not UNSET:
            fields = []
            for fields_item_data in _fields:
                fields_item = TypesField.from_dict(fields_item_data)

                fields.append(fields_item)

        file = d.pop("file", UNSET)

        frequency = d.pop("frequency", UNSET)

        ignore_active = d.pop("ignore_active", UNSET)

        lead = d.pop("lead", UNSET)

        plans = cast(list[str], d.pop("plans", UNSET))

        _plans_filter = d.pop("plans_filter", UNSET)
        plans_filter: TypesPlansFilter | Unset
        if isinstance(_plans_filter, Unset):
            plans_filter = UNSET
        else:
            plans_filter = TypesPlansFilter.from_dict(_plans_filter)

        timestamp = d.pop("timestamp", UNSET)

        types_project_schedule = cls(
            clients=clients,
            clients_filter=clients_filter,
            deals=deals,
            deals_filter=deals_filter,
            due=due,
            fields=fields,
            file=file,
            frequency=frequency,
            ignore_active=ignore_active,
            lead=lead,
            plans=plans,
            plans_filter=plans_filter,
            timestamp=timestamp,
        )

        types_project_schedule.additional_properties = d
        return types_project_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
