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_form_question import TypesFormQuestion
    from ..models.types_form_template_info import TypesFormTemplateInfo


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


@_attrs_define
class TypesFormTemplate:
    """
    Attributes:
        field_id (str | Unset):
        created_at (str | Unset):
        deleted_at (str | Unset):
        description (str | Unset):
        fields (str | Unset):
        hidden (bool | Unset):
        incomplete (int | Unset):
        info (TypesFormTemplateInfo | Unset):
        most_recent (str | Unset): For returning
        pdf (str | Unset):
        public (bool | Unset):
        questions (list[TypesFormQuestion] | Unset):
        replace_pdf (bool | Unset):
        tags (list[str] | Unset):
        team (str | Unset):
        title (str | Unset):
        total (int | Unset):
        type_ (str | Unset):
    """

    field_id: str | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    description: str | Unset = UNSET
    fields: str | Unset = UNSET
    hidden: bool | Unset = UNSET
    incomplete: int | Unset = UNSET
    info: TypesFormTemplateInfo | Unset = UNSET
    most_recent: str | Unset = UNSET
    pdf: str | Unset = UNSET
    public: bool | Unset = UNSET
    questions: list[TypesFormQuestion] | Unset = UNSET
    replace_pdf: bool | Unset = UNSET
    tags: list[str] | Unset = UNSET
    team: str | Unset = UNSET
    title: str | Unset = UNSET
    total: int | Unset = UNSET
    type_: 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

        created_at = self.created_at

        deleted_at = self.deleted_at

        description = self.description

        fields = self.fields

        hidden = self.hidden

        incomplete = self.incomplete

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

        most_recent = self.most_recent

        pdf = self.pdf

        public = self.public

        questions: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.questions, Unset):
            questions = []
            for questions_item_data in self.questions:
                questions_item = questions_item_data.to_dict()
                questions.append(questions_item)

        replace_pdf = self.replace_pdf

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

        team = self.team

        title = self.title

        total = self.total

        type_ = self.type_

        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 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 fields is not UNSET:
            field_dict["fields"] = fields
        if hidden is not UNSET:
            field_dict["hidden"] = hidden
        if incomplete is not UNSET:
            field_dict["incomplete"] = incomplete
        if info is not UNSET:
            field_dict["info"] = info
        if most_recent is not UNSET:
            field_dict["most_recent"] = most_recent
        if pdf is not UNSET:
            field_dict["pdf"] = pdf
        if public is not UNSET:
            field_dict["public"] = public
        if questions is not UNSET:
            field_dict["questions"] = questions
        if replace_pdf is not UNSET:
            field_dict["replace_pdf"] = replace_pdf
        if tags is not UNSET:
            field_dict["tags"] = tags
        if team is not UNSET:
            field_dict["team"] = team
        if title is not UNSET:
            field_dict["title"] = title
        if total is not UNSET:
            field_dict["total"] = total
        if type_ is not UNSET:
            field_dict["type"] = type_

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_form_question import TypesFormQuestion
        from ..models.types_form_template_info import TypesFormTemplateInfo

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

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

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

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

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

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

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

        _info = d.pop("info", UNSET)
        info: TypesFormTemplateInfo | Unset
        if isinstance(_info, Unset):
            info = UNSET
        else:
            info = TypesFormTemplateInfo.from_dict(_info)

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

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

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

        _questions = d.pop("questions", UNSET)
        questions: list[TypesFormQuestion] | Unset = UNSET
        if _questions is not UNSET:
            questions = []
            for questions_item_data in _questions:
                questions_item = TypesFormQuestion.from_dict(questions_item_data)

                questions.append(questions_item)

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

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

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

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

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

        type_ = d.pop("type", UNSET)

        types_form_template = cls(
            field_id=field_id,
            created_at=created_at,
            deleted_at=deleted_at,
            description=description,
            fields=fields,
            hidden=hidden,
            incomplete=incomplete,
            info=info,
            most_recent=most_recent,
            pdf=pdf,
            public=public,
            questions=questions,
            replace_pdf=replace_pdf,
            tags=tags,
            team=team,
            title=title,
            total=total,
            type_=type_,
        )

        types_form_template.additional_properties = d
        return types_form_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
