from __future__ import annotations

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

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

from ..models.image_variation_input_size_type_0 import ImageVariationInputSizeType0
from ..types import UNSET, Unset

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


@_attrs_define
class ImageVariationInput:
    """
    Attributes:
        image (None | str | Unset):
        size (ImageVariationInputSizeType0 | None | Unset):
    """

    image: None | str | Unset = UNSET
    size: ImageVariationInputSizeType0 | None | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        image: None | str | Unset
        if isinstance(self.image, Unset):
            image = UNSET
        else:
            image = self.image

        size: None | str | Unset
        if isinstance(self.size, Unset):
            size = UNSET
        elif isinstance(self.size, ImageVariationInputSizeType0):
            size = self.size.value
        else:
            size = self.size

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

        return field_dict

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

        def _parse_image(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        image = _parse_image(d.pop("image", UNSET))

        def _parse_size(data: object) -> ImageVariationInputSizeType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                size_type_0 = ImageVariationInputSizeType0(data)

                return size_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(ImageVariationInputSizeType0 | None | Unset, data)

        size = _parse_size(d.pop("size", UNSET))

        image_variation_input = cls(
            image=image,
            size=size,
        )

        image_variation_input.additional_properties = d
        return image_variation_input

    @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
