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_activity import TypesActivity
    from ..models.types_field import TypesField
    from ..models.types_project_schedule import TypesProjectSchedule
    from ..models.types_projects_aggregation import TypesProjectsAggregation
    from ..models.types_task_template import TypesTaskTemplate
    from ..models.types_trigger_config import TypesTriggerConfig


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


@_attrs_define
class TypesProjectTemplate:
    """
    Attributes:
        field_id (str | Unset):
        activity (list[TypesActivity] | Unset): For returning
        created_at (str | Unset): Time tracking
        deleted_at (str | Unset):
        description (str | Unset):
        estimated_time (int | Unset):
        fields (list[TypesField] | Unset):
        num_tasks (int | Unset):
        projects (TypesProjectsAggregation | Unset):
        schedule (list[TypesProjectSchedule] | Unset): Schedules to launch automatically
        tags (list[str] | Unset):
        tasks (list[TypesTaskTemplate] | Unset):
        team (str | Unset):
        title (str | Unset):
        triggers (list[TypesTriggerConfig] | Unset): Triggers - example: "Payroll Received"
        view (str | Unset): Estimated time to complete in minutes
    """

    field_id: str | Unset = UNSET
    activity: list[TypesActivity] | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    description: str | Unset = UNSET
    estimated_time: int | Unset = UNSET
    fields: list[TypesField] | Unset = UNSET
    num_tasks: int | Unset = UNSET
    projects: TypesProjectsAggregation | Unset = UNSET
    schedule: list[TypesProjectSchedule] | Unset = UNSET
    tags: list[str] | Unset = UNSET
    tasks: list[TypesTaskTemplate] | Unset = UNSET
    team: str | Unset = UNSET
    title: str | Unset = UNSET
    triggers: list[TypesTriggerConfig] | Unset = UNSET
    view: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        activity: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.activity, Unset):
            activity = []
            for activity_item_data in self.activity:
                activity_item = activity_item_data.to_dict()
                activity.append(activity_item)

        created_at = self.created_at

        deleted_at = self.deleted_at

        description = self.description

        estimated_time = self.estimated_time

        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)

        num_tasks = self.num_tasks

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

        schedule: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.schedule, Unset):
            schedule = []
            for schedule_item_data in self.schedule:
                schedule_item = schedule_item_data.to_dict()
                schedule.append(schedule_item)

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

        tasks: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.tasks, Unset):
            tasks = []
            for tasks_item_data in self.tasks:
                tasks_item = tasks_item_data.to_dict()
                tasks.append(tasks_item)

        team = self.team

        title = self.title

        triggers: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.triggers, Unset):
            triggers = []
            for triggers_item_data in self.triggers:
                triggers_item = triggers_item_data.to_dict()
                triggers.append(triggers_item)

        view = self.view

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if activity is not UNSET:
            field_dict["activity"] = activity
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if description is not UNSET:
            field_dict["description"] = description
        if estimated_time is not UNSET:
            field_dict["estimated_time"] = estimated_time
        if fields is not UNSET:
            field_dict["fields"] = fields
        if num_tasks is not UNSET:
            field_dict["num_tasks"] = num_tasks
        if projects is not UNSET:
            field_dict["projects"] = projects
        if schedule is not UNSET:
            field_dict["schedule"] = schedule
        if tags is not UNSET:
            field_dict["tags"] = tags
        if tasks is not UNSET:
            field_dict["tasks"] = tasks
        if team is not UNSET:
            field_dict["team"] = team
        if title is not UNSET:
            field_dict["title"] = title
        if triggers is not UNSET:
            field_dict["triggers"] = triggers
        if view is not UNSET:
            field_dict["view"] = view

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_activity import TypesActivity
        from ..models.types_field import TypesField
        from ..models.types_project_schedule import TypesProjectSchedule
        from ..models.types_projects_aggregation import TypesProjectsAggregation
        from ..models.types_task_template import TypesTaskTemplate
        from ..models.types_trigger_config import TypesTriggerConfig

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        _activity = d.pop("activity", UNSET)
        activity: list[TypesActivity] | Unset = UNSET
        if _activity is not UNSET:
            activity = []
            for activity_item_data in _activity:
                activity_item = TypesActivity.from_dict(activity_item_data)

                activity.append(activity_item)

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

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

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

        estimated_time = d.pop("estimated_time", 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)

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

        _projects = d.pop("projects", UNSET)
        projects: TypesProjectsAggregation | Unset
        if isinstance(_projects, Unset):
            projects = UNSET
        else:
            projects = TypesProjectsAggregation.from_dict(_projects)

        _schedule = d.pop("schedule", UNSET)
        schedule: list[TypesProjectSchedule] | Unset = UNSET
        if _schedule is not UNSET:
            schedule = []
            for schedule_item_data in _schedule:
                schedule_item = TypesProjectSchedule.from_dict(schedule_item_data)

                schedule.append(schedule_item)

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

        _tasks = d.pop("tasks", UNSET)
        tasks: list[TypesTaskTemplate] | Unset = UNSET
        if _tasks is not UNSET:
            tasks = []
            for tasks_item_data in _tasks:
                tasks_item = TypesTaskTemplate.from_dict(tasks_item_data)

                tasks.append(tasks_item)

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

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

        _triggers = d.pop("triggers", UNSET)
        triggers: list[TypesTriggerConfig] | Unset = UNSET
        if _triggers is not UNSET:
            triggers = []
            for triggers_item_data in _triggers:
                triggers_item = TypesTriggerConfig.from_dict(triggers_item_data)

                triggers.append(triggers_item)

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

        types_project_template = cls(
            field_id=field_id,
            activity=activity,
            created_at=created_at,
            deleted_at=deleted_at,
            description=description,
            estimated_time=estimated_time,
            fields=fields,
            num_tasks=num_tasks,
            projects=projects,
            schedule=schedule,
            tags=tags,
            tasks=tasks,
            team=team,
            title=title,
            triggers=triggers,
            view=view,
        )

        types_project_template.additional_properties = d
        return types_project_template

    @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
