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

from __future__ import annotations
from datetime import datetime
from pydantic import model_serializer
from tofupilot.v2.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from tofupilot.v2.utils import FieldMetadata, PathParamMetadata
from typing import List
from typing_extensions import Annotated, NotRequired, TypedDict


class PartGetRequestTypedDict(TypedDict):
    number: str
    r"""Part number of the part to retrieve."""


class PartGetRequest(BaseModel):
    number: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Part number of the part to retrieve."""


class PartGetCreatedByUserTypedDict(TypedDict):
    r"""User who created this part."""

    id: str
    r"""User ID."""
    name: Nullable[str]
    r"""User display name."""
    image: Nullable[str]
    r"""User profile image URL."""


class PartGetCreatedByUser(BaseModel):
    r"""User who created this part."""

    id: str
    r"""User ID."""

    name: Nullable[str]
    r"""User display name."""

    image: Nullable[str]
    r"""User profile image URL."""

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

        serialized = handler(self)

        m = {}

        for n, f in type(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 PartGetCreatedByStationTypedDict(TypedDict):
    r"""Station that created this part."""

    id: str
    r"""Station ID."""
    name: str
    r"""Station name."""
    image: Nullable[str]
    r"""Station image URL."""


class PartGetCreatedByStation(BaseModel):
    r"""Station that created this part."""

    id: str
    r"""Station ID."""

    name: str
    r"""Station name."""

    image: Nullable[str]
    r"""Station image URL."""

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

        serialized = handler(self)

        m = {}

        for n, f in type(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 PartGetRevisionTypedDict(TypedDict):
    id: str
    r"""Revision ID."""
    number: str
    r"""Revision number."""
    created_at: datetime
    r"""ISO 8601 timestamp when the revision was created."""
    image: Nullable[str]
    r"""Revision image URL."""


class PartGetRevision(BaseModel):
    id: str
    r"""Revision ID."""

    number: str
    r"""Revision number."""

    created_at: datetime
    r"""ISO 8601 timestamp when the revision was created."""

    image: Nullable[str]
    r"""Revision image URL."""

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

        serialized = handler(self)

        m = {}

        for n, f in type(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 PartGetResponseTypedDict(TypedDict):
    r"""Part retrieved successfully"""

    id: str
    r"""Unique identifier for the part."""
    number: str
    r"""Part number."""
    name: str
    r"""Part name."""
    created_at: datetime
    r"""ISO 8601 timestamp when the part was created."""
    revisions: List[PartGetRevisionTypedDict]
    r"""List of revisions for this part."""
    created_by_user: NotRequired[Nullable[PartGetCreatedByUserTypedDict]]
    r"""User who created this part."""
    created_by_station: NotRequired[Nullable[PartGetCreatedByStationTypedDict]]
    r"""Station that created this part."""


class PartGetResponse(BaseModel):
    r"""Part retrieved successfully"""

    id: str
    r"""Unique identifier for the part."""

    number: str
    r"""Part number."""

    name: str
    r"""Part name."""

    created_at: datetime
    r"""ISO 8601 timestamp when the part was created."""

    revisions: List[PartGetRevision]
    r"""List of revisions for this part."""

    created_by_user: OptionalNullable[PartGetCreatedByUser] = UNSET
    r"""User who created this part."""

    created_by_station: OptionalNullable[PartGetCreatedByStation] = UNSET
    r"""Station that created this part."""

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

        serialized = handler(self)

        m = {}

        for n, f in type(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
