from __future__ import annotations

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

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

from ..models.image_edit_response_format_type_0 import ImageEditResponseFormatType0
from ..models.image_edit_size_type_0 import ImageEditSizeType0
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.image_edit_extra_headers_type_0 import ImageEditExtraHeadersType0
    from ..models.image_edit_extra_query_type_0 import ImageEditExtraQueryType0


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


@_attrs_define
class ImageEdit:
    """
    Attributes:
        image (str):
        prompt (str):
        extra_headers (ImageEditExtraHeadersType0 | None | Unset):
        extra_query (ImageEditExtraQueryType0 | None | Unset):
        extra_body (Any | None | Unset):
        timeout (float | None | Unset):
        mask (None | str | Unset):
        model (Literal['dall-e-3'] | None | str | Unset):  Default: 'dall-e-3'.
        n (int | None | Unset):  Default: 1.
        response_format (ImageEditResponseFormatType0 | None | Unset):
        size (ImageEditSizeType0 | None | Unset):
        user (None | str | Unset):
    """

    image: str
    prompt: str
    extra_headers: ImageEditExtraHeadersType0 | None | Unset = UNSET
    extra_query: ImageEditExtraQueryType0 | None | Unset = UNSET
    extra_body: Any | None | Unset = UNSET
    timeout: float | None | Unset = UNSET
    mask: None | str | Unset = UNSET
    model: Literal["dall-e-3"] | None | str | Unset = "dall-e-3"
    n: int | None | Unset = 1
    response_format: ImageEditResponseFormatType0 | None | Unset = UNSET
    size: ImageEditSizeType0 | None | Unset = UNSET
    user: None | str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        from ..models.image_edit_extra_headers_type_0 import ImageEditExtraHeadersType0
        from ..models.image_edit_extra_query_type_0 import ImageEditExtraQueryType0

        image: str
        image = self.image

        prompt = self.prompt

        extra_headers: dict[str, Any] | None | Unset
        if isinstance(self.extra_headers, Unset):
            extra_headers = UNSET
        elif isinstance(self.extra_headers, ImageEditExtraHeadersType0):
            extra_headers = self.extra_headers.to_dict()
        else:
            extra_headers = self.extra_headers

        extra_query: dict[str, Any] | None | Unset
        if isinstance(self.extra_query, Unset):
            extra_query = UNSET
        elif isinstance(self.extra_query, ImageEditExtraQueryType0):
            extra_query = self.extra_query.to_dict()
        else:
            extra_query = self.extra_query

        extra_body: Any | None | Unset
        if isinstance(self.extra_body, Unset):
            extra_body = UNSET
        else:
            extra_body = self.extra_body

        timeout: float | None | Unset
        if isinstance(self.timeout, Unset):
            timeout = UNSET
        else:
            timeout = self.timeout

        mask: None | str | Unset
        if isinstance(self.mask, Unset):
            mask = UNSET
        else:
            mask = self.mask

        model: Literal["dall-e-3"] | None | str | Unset
        if isinstance(self.model, Unset):
            model = UNSET
        else:
            model = self.model

        n: int | None | Unset
        if isinstance(self.n, Unset):
            n = UNSET
        else:
            n = self.n

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

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

        user: None | str | Unset
        if isinstance(self.user, Unset):
            user = UNSET
        else:
            user = self.user

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "image": image,
                "prompt": prompt,
            }
        )
        if extra_headers is not UNSET:
            field_dict["extra_headers"] = extra_headers
        if extra_query is not UNSET:
            field_dict["extra_query"] = extra_query
        if extra_body is not UNSET:
            field_dict["extra_body"] = extra_body
        if timeout is not UNSET:
            field_dict["timeout"] = timeout
        if mask is not UNSET:
            field_dict["mask"] = mask
        if model is not UNSET:
            field_dict["model"] = model
        if n is not UNSET:
            field_dict["n"] = n
        if response_format is not UNSET:
            field_dict["response_format"] = response_format
        if size is not UNSET:
            field_dict["size"] = size
        if user is not UNSET:
            field_dict["user"] = user

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.image_edit_extra_headers_type_0 import ImageEditExtraHeadersType0
        from ..models.image_edit_extra_query_type_0 import ImageEditExtraQueryType0

        d = dict(src_dict)

        def _parse_image(data: object) -> str:
            return cast(str, data)

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

        prompt = d.pop("prompt")

        def _parse_extra_headers(data: object) -> ImageEditExtraHeadersType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                extra_headers_type_0 = ImageEditExtraHeadersType0.from_dict(data)

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

        extra_headers = _parse_extra_headers(d.pop("extra_headers", UNSET))

        def _parse_extra_query(data: object) -> ImageEditExtraQueryType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                extra_query_type_0 = ImageEditExtraQueryType0.from_dict(data)

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

        extra_query = _parse_extra_query(d.pop("extra_query", UNSET))

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

        extra_body = _parse_extra_body(d.pop("extra_body", UNSET))

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

        timeout = _parse_timeout(d.pop("timeout", UNSET))

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

        mask = _parse_mask(d.pop("mask", UNSET))

        def _parse_model(data: object) -> Literal["dall-e-3"] | None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            model_type_1 = cast(Literal["dall-e-3"], data)
            if model_type_1 != "dall-e-3":
                raise ValueError(f"model_type_1 must match const 'dall-e-3', got '{model_type_1}'")
            return model_type_1
            return cast(Literal["dall-e-3"] | None | str | Unset, data)

        model = _parse_model(d.pop("model", UNSET))

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

        n = _parse_n(d.pop("n", UNSET))

        def _parse_response_format(data: object) -> ImageEditResponseFormatType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                response_format_type_0 = ImageEditResponseFormatType0(data)

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

        response_format = _parse_response_format(d.pop("response_format", UNSET))

        def _parse_size(data: object) -> ImageEditSizeType0 | 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 = ImageEditSizeType0(data)

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

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

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

        user = _parse_user(d.pop("user", UNSET))

        image_edit = cls(
            image=image,
            prompt=prompt,
            extra_headers=extra_headers,
            extra_query=extra_query,
            extra_body=extra_body,
            timeout=timeout,
            mask=mask,
            model=model,
            n=n,
            response_format=response_format,
            size=size,
            user=user,
        )

        image_edit.additional_properties = d
        return image_edit

    @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
