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_project import TypesProject


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


@_attrs_define
class PkgRoutesDashboardTemplateGroup:
    """
    Attributes:
        projects (list[TypesProject] | Unset):
        template (str | Unset):
        title (str | Unset):
    """

    projects: list[TypesProject] | Unset = UNSET
    template: str | Unset = UNSET
    title: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        projects: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.projects, Unset):
            projects = []
            for projects_item_data in self.projects:
                projects_item = projects_item_data.to_dict()
                projects.append(projects_item)

        template = self.template

        title = self.title

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if projects is not UNSET:
            field_dict["projects"] = projects
        if template is not UNSET:
            field_dict["template"] = template
        if title is not UNSET:
            field_dict["title"] = title

        return field_dict

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

        d = dict(src_dict)
        _projects = d.pop("projects", UNSET)
        projects: list[TypesProject] | Unset = UNSET
        if _projects is not UNSET:
            projects = []
            for projects_item_data in _projects:
                projects_item = TypesProject.from_dict(projects_item_data)

                projects.append(projects_item)

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

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

        pkg_routes_dashboard_template_group = cls(
            projects=projects,
            template=template,
            title=title,
        )

        pkg_routes_dashboard_template_group.additional_properties = d
        return pkg_routes_dashboard_template_group

    @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
