"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
import httpx
from leonardo_ai_sdk.models.shared import (
    custom_model_type as shared_custom_model_type,
    job_status as shared_job_status,
    sd_versions as shared_sd_versions,
)
from leonardo_ai_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from leonardo_ai_sdk.utils import FieldMetadata, PathParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class GetCustomModelsByUserIDRequestTypedDict(TypedDict):
    user_id: str
    r"""The ID of the user to return."""


class GetCustomModelsByUserIDRequest(BaseModel):
    user_id: Annotated[
        str,
        pydantic.Field(alias="userId"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]
    r"""The ID of the user to return."""


class GetCustomModelsByUserIDCustomModelsTypedDict(TypedDict):
    r"""columns and relationships of \"custom_models\" """

    created_at: NotRequired[str]
    description: NotRequired[str]
    id: NotRequired[Nullable[str]]
    instance_prompt: NotRequired[Nullable[str]]
    model_height: NotRequired[int]
    model_width: NotRequired[int]
    name: NotRequired[str]
    public: NotRequired[bool]
    sd_version: NotRequired[shared_sd_versions.SdVersions]
    r"""The base version of stable diffusion to use if not using a custom model. v1_5 is 1.5, v2 is 2.1, if not specified it will default to v1_5. Also includes SDXL and SDXL Lightning models"""
    status: NotRequired[shared_job_status.JobStatus]
    r"""The status of the current task."""
    type: NotRequired[shared_custom_model_type.CustomModelType]
    r"""The category the most accurately reflects the model."""
    updated_at: NotRequired[str]


class GetCustomModelsByUserIDCustomModels(BaseModel):
    r"""columns and relationships of \"custom_models\" """

    created_at: Annotated[Optional[str], pydantic.Field(alias="createdAt")] = None

    description: Optional[str] = None

    id: OptionalNullable[str] = UNSET

    instance_prompt: Annotated[
        OptionalNullable[str], pydantic.Field(alias="instancePrompt")
    ] = UNSET

    model_height: Annotated[Optional[int], pydantic.Field(alias="modelHeight")] = None

    model_width: Annotated[Optional[int], pydantic.Field(alias="modelWidth")] = None

    name: Optional[str] = None

    public: Optional[bool] = None

    sd_version: Annotated[
        Optional[shared_sd_versions.SdVersions], pydantic.Field(alias="sdVersion")
    ] = None
    r"""The base version of stable diffusion to use if not using a custom model. v1_5 is 1.5, v2 is 2.1, if not specified it will default to v1_5. Also includes SDXL and SDXL Lightning models"""

    status: Optional[shared_job_status.JobStatus] = None
    r"""The status of the current task."""

    type: Optional[shared_custom_model_type.CustomModelType] = (
        shared_custom_model_type.CustomModelType.GENERAL
    )
    r"""The category the most accurately reflects the model."""

    updated_at: Annotated[Optional[str], pydantic.Field(alias="updatedAt")] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "createdAt",
            "description",
            "id",
            "instancePrompt",
            "modelHeight",
            "modelWidth",
            "name",
            "public",
            "sdVersion",
            "status",
            "type",
            "updatedAt",
        ]
        nullable_fields = ["id", "instancePrompt"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class GetCustomModelsByUserIDResponseBodyTypedDict(TypedDict):
    r"""Responses for GET /models/user/{userId}"""

    custom_models: NotRequired[
        Nullable[List[GetCustomModelsByUserIDCustomModelsTypedDict]]
    ]


class GetCustomModelsByUserIDResponseBody(BaseModel):
    r"""Responses for GET /models/user/{userId}"""

    custom_models: OptionalNullable[List[GetCustomModelsByUserIDCustomModels]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["custom_models"]
        nullable_fields = ["custom_models"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class GetCustomModelsByUserIDResponseTypedDict(TypedDict):
    content_type: str
    r"""HTTP response content type for this operation"""
    status_code: int
    r"""HTTP response status code for this operation"""
    raw_response: httpx.Response
    r"""Raw HTTP response; suitable for custom response parsing"""
    object: NotRequired[GetCustomModelsByUserIDResponseBodyTypedDict]
    r"""Responses for GET /models/user/{userId}"""


class GetCustomModelsByUserIDResponse(BaseModel):
    content_type: str
    r"""HTTP response content type for this operation"""

    status_code: int
    r"""HTTP response status code for this operation"""

    raw_response: httpx.Response
    r"""Raw HTTP response; suitable for custom response parsing"""

    object: Optional[GetCustomModelsByUserIDResponseBody] = None
    r"""Responses for GET /models/user/{userId}"""
