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_client_task_data_template import TypesClientTaskDataTemplate
    from ..models.types_field import TypesField
    from ..models.types_internal_task_data_template import TypesInternalTaskDataTemplate


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


@_attrs_define
class TypesTaskTemplate:
    """
    Attributes:
        assignee (str | Unset):
        automation (str | Unset): Automation
        automation_config (list[TypesField] | Unset):
        client_task_data (TypesClientTaskDataTemplate | Unset):
        client_task_type (str | Unset):
        description (str | Unset):
        due_after_days (int | Unset):
        due_static (str | Unset): Due - can either be a specific date or relative to the project launch date
        fields_to_complete (list[str] | Unset):
        internal_task_data (TypesInternalTaskDataTemplate | Unset):
        internal_task_type (str | Unset):
        log_completion_to (str | Unset):
        log_completion_type (str | Unset): Log completion time to project variable?
        notes (str | Unset):
    """

    assignee: str | Unset = UNSET
    automation: str | Unset = UNSET
    automation_config: list[TypesField] | Unset = UNSET
    client_task_data: TypesClientTaskDataTemplate | Unset = UNSET
    client_task_type: str | Unset = UNSET
    description: str | Unset = UNSET
    due_after_days: int | Unset = UNSET
    due_static: str | Unset = UNSET
    fields_to_complete: list[str] | Unset = UNSET
    internal_task_data: TypesInternalTaskDataTemplate | Unset = UNSET
    internal_task_type: str | Unset = UNSET
    log_completion_to: str | Unset = UNSET
    log_completion_type: str | Unset = UNSET
    notes: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        automation = self.automation

        automation_config: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.automation_config, Unset):
            automation_config = []
            for automation_config_item_data in self.automation_config:
                automation_config_item = automation_config_item_data.to_dict()
                automation_config.append(automation_config_item)

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

        client_task_type = self.client_task_type

        description = self.description

        due_after_days = self.due_after_days

        due_static = self.due_static

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

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

        internal_task_type = self.internal_task_type

        log_completion_to = self.log_completion_to

        log_completion_type = self.log_completion_type

        notes = self.notes

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if assignee is not UNSET:
            field_dict["assignee"] = assignee
        if automation is not UNSET:
            field_dict["automation"] = automation
        if automation_config is not UNSET:
            field_dict["automation_config"] = automation_config
        if client_task_data is not UNSET:
            field_dict["client_task_data"] = client_task_data
        if client_task_type is not UNSET:
            field_dict["client_task_type"] = client_task_type
        if description is not UNSET:
            field_dict["description"] = description
        if due_after_days is not UNSET:
            field_dict["due_after_days"] = due_after_days
        if due_static is not UNSET:
            field_dict["due_static"] = due_static
        if fields_to_complete is not UNSET:
            field_dict["fields_to_complete"] = fields_to_complete
        if internal_task_data is not UNSET:
            field_dict["internal_task_data"] = internal_task_data
        if internal_task_type is not UNSET:
            field_dict["internal_task_type"] = internal_task_type
        if log_completion_to is not UNSET:
            field_dict["log_completion_to"] = log_completion_to
        if log_completion_type is not UNSET:
            field_dict["log_completion_type"] = log_completion_type
        if notes is not UNSET:
            field_dict["notes"] = notes

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_client_task_data_template import TypesClientTaskDataTemplate
        from ..models.types_field import TypesField
        from ..models.types_internal_task_data_template import TypesInternalTaskDataTemplate

        d = dict(src_dict)
        assignee = d.pop("assignee", UNSET)

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

        _automation_config = d.pop("automation_config", UNSET)
        automation_config: list[TypesField] | Unset = UNSET
        if _automation_config is not UNSET:
            automation_config = []
            for automation_config_item_data in _automation_config:
                automation_config_item = TypesField.from_dict(automation_config_item_data)

                automation_config.append(automation_config_item)

        _client_task_data = d.pop("client_task_data", UNSET)
        client_task_data: TypesClientTaskDataTemplate | Unset
        if isinstance(_client_task_data, Unset):
            client_task_data = UNSET
        else:
            client_task_data = TypesClientTaskDataTemplate.from_dict(_client_task_data)

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

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

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

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

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

        _internal_task_data = d.pop("internal_task_data", UNSET)
        internal_task_data: TypesInternalTaskDataTemplate | Unset
        if isinstance(_internal_task_data, Unset):
            internal_task_data = UNSET
        else:
            internal_task_data = TypesInternalTaskDataTemplate.from_dict(_internal_task_data)

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

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

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

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

        types_task_template = cls(
            assignee=assignee,
            automation=automation,
            automation_config=automation_config,
            client_task_data=client_task_data,
            client_task_type=client_task_type,
            description=description,
            due_after_days=due_after_days,
            due_static=due_static,
            fields_to_complete=fields_to_complete,
            internal_task_data=internal_task_data,
            internal_task_type=internal_task_type,
            log_completion_to=log_completion_to,
            log_completion_type=log_completion_type,
            notes=notes,
        )

        types_task_template.additional_properties = d
        return types_task_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
