from typing import TYPE_CHECKING, Any, Dict, List, Literal, Type, TypeVar, Union

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

from ..models.field_lookup_system_type import FieldLookupSystemType
from ..models.field_lookup_validation_status import FieldLookupValidationStatus
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.field_boolean import FieldBoolean
    from ..models.field_date import FieldDate
    from ..models.field_editor import FieldEditor
    from ..models.field_file import FieldFile
    from ..models.field_float import FieldFloat
    from ..models.field_integer import FieldInteger
    from ..models.field_reference import FieldReference
    from ..models.field_select import FieldSelect
    from ..models.field_text import FieldText
    from ..models.field_url import FieldUrl
    from ..models.field_user import FieldUser
    from ..models.invalid_data import InvalidData


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


@_attrs_define
class FieldLookup:
    """
    Attributes:
        column_id (str):
        validation_status (FieldLookupValidationStatus):
        type (Literal['lookup']):
        version (Union[Unset, float]):
        invalid_data (Union[Unset, InvalidData]):
        system_type (Union[Unset, FieldLookupSystemType]):
        value (Union['FieldBoolean', 'FieldDate', 'FieldEditor', 'FieldFile', 'FieldFloat', 'FieldInteger',
            'FieldReference', 'FieldSelect', 'FieldText', 'FieldUrl', 'FieldUser', Unset]):
    """

    column_id: str
    validation_status: FieldLookupValidationStatus
    type: Literal["lookup"]
    version: Union[Unset, float] = UNSET
    invalid_data: Union[Unset, "InvalidData"] = UNSET
    system_type: Union[Unset, FieldLookupSystemType] = UNSET
    value: Union[
        "FieldBoolean",
        "FieldDate",
        "FieldEditor",
        "FieldFile",
        "FieldFloat",
        "FieldInteger",
        "FieldReference",
        "FieldSelect",
        "FieldText",
        "FieldUrl",
        "FieldUser",
        Unset,
    ] = UNSET
    additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> Dict[str, Any]:
        from ..models.field_boolean import FieldBoolean
        from ..models.field_date import FieldDate
        from ..models.field_editor import FieldEditor
        from ..models.field_file import FieldFile
        from ..models.field_float import FieldFloat
        from ..models.field_integer import FieldInteger
        from ..models.field_reference import FieldReference
        from ..models.field_select import FieldSelect
        from ..models.field_text import FieldText
        from ..models.field_url import FieldUrl

        column_id = self.column_id

        validation_status = self.validation_status.value

        type = self.type

        version = self.version

        invalid_data: Union[Unset, Dict[str, Any]] = UNSET
        if not isinstance(self.invalid_data, Unset):
            invalid_data = self.invalid_data.to_dict()

        system_type: Union[Unset, str] = UNSET
        if not isinstance(self.system_type, Unset):
            system_type = self.system_type.value

        value: Union[Dict[str, Any], Unset]
        if isinstance(self.value, Unset):
            value = UNSET
        elif isinstance(self.value, FieldText):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldInteger):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldFloat):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldBoolean):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldReference):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldEditor):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldFile):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldSelect):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldDate):
            value = self.value.to_dict()
        elif isinstance(self.value, FieldUrl):
            value = self.value.to_dict()
        else:
            value = self.value.to_dict()

        field_dict: Dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "columnId": column_id,
                "validationStatus": validation_status,
                "type": type,
            }
        )
        if version is not UNSET:
            field_dict["version"] = version
        if invalid_data is not UNSET:
            field_dict["invalidData"] = invalid_data
        if system_type is not UNSET:
            field_dict["systemType"] = system_type
        if value is not UNSET:
            field_dict["value"] = value

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        from ..models.field_boolean import FieldBoolean
        from ..models.field_date import FieldDate
        from ..models.field_editor import FieldEditor
        from ..models.field_file import FieldFile
        from ..models.field_float import FieldFloat
        from ..models.field_integer import FieldInteger
        from ..models.field_reference import FieldReference
        from ..models.field_select import FieldSelect
        from ..models.field_text import FieldText
        from ..models.field_url import FieldUrl
        from ..models.field_user import FieldUser
        from ..models.invalid_data import InvalidData

        d = src_dict.copy()
        column_id = d.pop("columnId")

        validation_status = FieldLookupValidationStatus(d.pop("validationStatus"))

        type = d.pop("type")

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

        _invalid_data = d.pop("invalidData", UNSET)
        invalid_data: Union[Unset, InvalidData]
        if isinstance(_invalid_data, Unset):
            invalid_data = UNSET
        else:
            invalid_data = InvalidData.from_dict(_invalid_data)

        _system_type = d.pop("systemType", UNSET)
        system_type: Union[Unset, FieldLookupSystemType]
        if isinstance(_system_type, Unset):
            system_type = UNSET
        else:
            system_type = FieldLookupSystemType(_system_type)

        def _parse_value(
            data: object,
        ) -> Union[
            "FieldBoolean",
            "FieldDate",
            "FieldEditor",
            "FieldFile",
            "FieldFloat",
            "FieldInteger",
            "FieldReference",
            "FieldSelect",
            "FieldText",
            "FieldUrl",
            "FieldUser",
            Unset,
        ]:
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_0 = FieldText.from_dict(data)

                return value_type_0
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_1 = FieldInteger.from_dict(data)

                return value_type_1
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_2 = FieldFloat.from_dict(data)

                return value_type_2
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_3 = FieldBoolean.from_dict(data)

                return value_type_3
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_4 = FieldReference.from_dict(data)

                return value_type_4
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_5 = FieldEditor.from_dict(data)

                return value_type_5
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_6 = FieldFile.from_dict(data)

                return value_type_6
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_7 = FieldSelect.from_dict(data)

                return value_type_7
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_8 = FieldDate.from_dict(data)

                return value_type_8
            except:  # noqa: E722
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                value_type_9 = FieldUrl.from_dict(data)

                return value_type_9
            except:  # noqa: E722
                pass
            if not isinstance(data, dict):
                raise TypeError()
            value_type_10 = FieldUser.from_dict(data)

            return value_type_10

        value = _parse_value(d.pop("value", UNSET))

        field_lookup = cls(
            column_id=column_id,
            validation_status=validation_status,
            type=type,
            version=version,
            invalid_data=invalid_data,
            system_type=system_type,
            value=value,
        )

        field_lookup.additional_properties = d
        return field_lookup

    @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
