from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.fillable_field_data_type import FillableFieldDataType
from ..types import UNSET, Unset

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


@_attrs_define
class FillableField:
    """
    Attributes:
        key (str | Unset):
        required (bool | Unset):
        hint (str | Unset):
        data_type (FillableFieldDataType | Unset):
        font_size (float | Unset):
        page (float | Unset):
        x (float | Unset):
        y (float | Unset):
        width (float | Unset):
        height (float | Unset):
    """

    key: str | Unset = UNSET
    required: bool | Unset = UNSET
    hint: str | Unset = UNSET
    data_type: FillableFieldDataType | Unset = UNSET
    font_size: float | Unset = UNSET
    page: float | Unset = UNSET
    x: float | Unset = UNSET
    y: float | Unset = UNSET
    width: float | Unset = UNSET
    height: float | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        required = self.required

        hint = self.hint

        data_type: str | Unset = UNSET
        if not isinstance(self.data_type, Unset):
            data_type = self.data_type.value

        font_size = self.font_size

        page = self.page

        x = self.x

        y = self.y

        width = self.width

        height = self.height

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if key is not UNSET:
            field_dict["key"] = key
        if required is not UNSET:
            field_dict["required"] = required
        if hint is not UNSET:
            field_dict["hint"] = hint
        if data_type is not UNSET:
            field_dict["dataType"] = data_type
        if font_size is not UNSET:
            field_dict["fontSize"] = font_size
        if page is not UNSET:
            field_dict["page"] = page
        if x is not UNSET:
            field_dict["x"] = x
        if y is not UNSET:
            field_dict["y"] = y
        if width is not UNSET:
            field_dict["width"] = width
        if height is not UNSET:
            field_dict["height"] = height

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        key = d.pop("key", UNSET)

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

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

        _data_type = d.pop("dataType", UNSET)
        data_type: FillableFieldDataType | Unset
        if isinstance(_data_type, Unset):
            data_type = UNSET
        else:
            data_type = FillableFieldDataType(_data_type)

        font_size = d.pop("fontSize", UNSET)

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

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

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

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

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

        fillable_field = cls(
            key=key,
            required=required,
            hint=hint,
            data_type=data_type,
            font_size=font_size,
            page=page,
            x=x,
            y=y,
            width=width,
            height=height,
        )

        fillable_field.additional_properties = d
        return fillable_field

    @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
