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.legacytypes_condition import LegacytypesCondition
    from ..models.legacytypes_form_question_data import LegacytypesFormQuestionData


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


@_attrs_define
class LegacytypesFormQuestion:
    """
    Attributes:
        field_id (str | Unset):
        conditions (list[LegacytypesCondition] | Unset):
        data (LegacytypesFormQuestionData | Unset):
        default (Any | Unset):
        hint (str | Unset):
        key (str | Unset):
        link (str | Unset):
        multiple (bool | Unset):
        on_type (str | Unset):
        options (list[str] | Unset):
        required (bool | Unset):
        title (str | Unset):
        type_ (str | Unset):
    """

    field_id: str | Unset = UNSET
    conditions: list[LegacytypesCondition] | Unset = UNSET
    data: LegacytypesFormQuestionData | Unset = UNSET
    default: Any | Unset = UNSET
    hint: str | Unset = UNSET
    key: str | Unset = UNSET
    link: str | Unset = UNSET
    multiple: bool | Unset = UNSET
    on_type: str | Unset = UNSET
    options: list[str] | Unset = UNSET
    required: bool | Unset = UNSET
    title: str | 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

        conditions: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.conditions, Unset):
            conditions = []
            for conditions_item_data in self.conditions:
                conditions_item = conditions_item_data.to_dict()
                conditions.append(conditions_item)

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

        default = self.default

        hint = self.hint

        key = self.key

        link = self.link

        multiple = self.multiple

        on_type = self.on_type

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

        required = self.required

        title = self.title

        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 conditions is not UNSET:
            field_dict["conditions"] = conditions
        if data is not UNSET:
            field_dict["data"] = data
        if default is not UNSET:
            field_dict["default"] = default
        if hint is not UNSET:
            field_dict["hint"] = hint
        if key is not UNSET:
            field_dict["key"] = key
        if link is not UNSET:
            field_dict["link"] = link
        if multiple is not UNSET:
            field_dict["multiple"] = multiple
        if on_type is not UNSET:
            field_dict["on_type"] = on_type
        if options is not UNSET:
            field_dict["options"] = options
        if required is not UNSET:
            field_dict["required"] = required
        if title is not UNSET:
            field_dict["title"] = title
        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.legacytypes_condition import LegacytypesCondition
        from ..models.legacytypes_form_question_data import LegacytypesFormQuestionData

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

        _conditions = d.pop("conditions", UNSET)
        conditions: list[LegacytypesCondition] | Unset = UNSET
        if _conditions is not UNSET:
            conditions = []
            for conditions_item_data in _conditions:
                conditions_item = LegacytypesCondition.from_dict(conditions_item_data)

                conditions.append(conditions_item)

        _data = d.pop("data", UNSET)
        data: LegacytypesFormQuestionData | Unset
        if isinstance(_data, Unset):
            data = UNSET
        else:
            data = LegacytypesFormQuestionData.from_dict(_data)

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

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

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

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

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

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

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

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

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

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

        legacytypes_form_question = cls(
            field_id=field_id,
            conditions=conditions,
            data=data,
            default=default,
            hint=hint,
            key=key,
            link=link,
            multiple=multiple,
            on_type=on_type,
            options=options,
            required=required,
            title=title,
            type_=type_,
        )

        legacytypes_form_question.additional_properties = d
        return legacytypes_form_question

    @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
