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 ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_activity import TypesActivity
    from ..models.types_element import TypesElement
    from ..models.types_id_title import TypesIDTitle
    from ..models.types_view_default_for import TypesViewDefaultFor


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


@_attrs_define
class TypesView:
    """
    Attributes:
        field_id (str | Unset):
        activity (list[TypesActivity] | Unset): For returning
        created_at (str | Unset):
        default_for (TypesViewDefaultFor | Unset): This will be the default team for resources (clients/plans) that meet
            the criteria
            Sample keys: status, type, etc.
        deleted_at (str | Unset):
        description (str | Unset):
        elements (list[TypesElement] | Unset):
        name (str | Unset):
        on_type (str | Unset): client, plan, project OR all/empty
        resources (int | Unset):
        team (str | Unset):
        templates (list[TypesIDTitle] | Unset):
    """

    field_id: str | Unset = UNSET
    activity: list[TypesActivity] | Unset = UNSET
    created_at: str | Unset = UNSET
    default_for: TypesViewDefaultFor | Unset = UNSET
    deleted_at: str | Unset = UNSET
    description: str | Unset = UNSET
    elements: list[TypesElement] | Unset = UNSET
    name: str | Unset = UNSET
    on_type: str | Unset = UNSET
    resources: int | Unset = UNSET
    team: str | Unset = UNSET
    templates: list[TypesIDTitle] | 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

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

        deleted_at = self.deleted_at

        description = self.description

        elements: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.elements, Unset):
            elements = []
            for elements_item_data in self.elements:
                elements_item = elements_item_data.to_dict()
                elements.append(elements_item)

        name = self.name

        on_type = self.on_type

        resources = self.resources

        team = self.team

        templates: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.templates, Unset):
            templates = []
            for templates_item_data in self.templates:
                templates_item = templates_item_data.to_dict()
                templates.append(templates_item)

        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 default_for is not UNSET:
            field_dict["default_for"] = default_for
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if description is not UNSET:
            field_dict["description"] = description
        if elements is not UNSET:
            field_dict["elements"] = elements
        if name is not UNSET:
            field_dict["name"] = name
        if on_type is not UNSET:
            field_dict["on_type"] = on_type
        if resources is not UNSET:
            field_dict["resources"] = resources
        if team is not UNSET:
            field_dict["team"] = team
        if templates is not UNSET:
            field_dict["templates"] = templates

        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_element import TypesElement
        from ..models.types_id_title import TypesIDTitle
        from ..models.types_view_default_for import TypesViewDefaultFor

        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)

        _default_for = d.pop("default_for", UNSET)
        default_for: TypesViewDefaultFor | Unset
        if isinstance(_default_for, Unset):
            default_for = UNSET
        else:
            default_for = TypesViewDefaultFor.from_dict(_default_for)

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

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

        _elements = d.pop("elements", UNSET)
        elements: list[TypesElement] | Unset = UNSET
        if _elements is not UNSET:
            elements = []
            for elements_item_data in _elements:
                elements_item = TypesElement.from_dict(elements_item_data)

                elements.append(elements_item)

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

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

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

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

        _templates = d.pop("templates", UNSET)
        templates: list[TypesIDTitle] | Unset = UNSET
        if _templates is not UNSET:
            templates = []
            for templates_item_data in _templates:
                templates_item = TypesIDTitle.from_dict(templates_item_data)

                templates.append(templates_item)

        types_view = cls(
            field_id=field_id,
            activity=activity,
            created_at=created_at,
            default_for=default_for,
            deleted_at=deleted_at,
            description=description,
            elements=elements,
            name=name,
            on_type=on_type,
            resources=resources,
            team=team,
            templates=templates,
        )

        types_view.additional_properties = d
        return types_view

    @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
