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_tasks_aggregation import TypesTasksAggregation


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


@_attrs_define
class TypesProjectsAggregation:
    """
    Attributes:
        complete (int | Unset):
        in_progress (int | Unset):
        on_hold (int | Unset):
        overdue (int | Unset):
        projects (list[str] | Unset):
        tasks (list[TypesTasksAggregation] | Unset):
        total (int | Unset):
    """

    complete: int | Unset = UNSET
    in_progress: int | Unset = UNSET
    on_hold: int | Unset = UNSET
    overdue: int | Unset = UNSET
    projects: list[str] | Unset = UNSET
    tasks: list[TypesTasksAggregation] | Unset = UNSET
    total: int | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        in_progress = self.in_progress

        on_hold = self.on_hold

        overdue = self.overdue

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

        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)

        total = self.total

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if complete is not UNSET:
            field_dict["complete"] = complete
        if in_progress is not UNSET:
            field_dict["in_progress"] = in_progress
        if on_hold is not UNSET:
            field_dict["on_hold"] = on_hold
        if overdue is not UNSET:
            field_dict["overdue"] = overdue
        if projects is not UNSET:
            field_dict["projects"] = projects
        if tasks is not UNSET:
            field_dict["tasks"] = tasks
        if total is not UNSET:
            field_dict["total"] = total

        return field_dict

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

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

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

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

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

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

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

                tasks.append(tasks_item)

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

        types_projects_aggregation = cls(
            complete=complete,
            in_progress=in_progress,
            on_hold=on_hold,
            overdue=overdue,
            projects=projects,
            tasks=tasks,
            total=total,
        )

        types_projects_aggregation.additional_properties = d
        return types_projects_aggregation

    @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
