"""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, UNSET_SENTINEL
from tofupilot.v2.utils import FieldMetadata, PathParamMetadata
from typing import List
from typing_extensions import Annotated, TypedDict


class PartGetRevisionRequestTypedDict(TypedDict):
    part_number: str
    r"""Part number that the revision belongs to."""
    revision_number: str
    r"""Revision number to retrieve."""


class PartGetRevisionRequest(BaseModel):
    part_number: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Part number that the revision belongs to."""

    revision_number: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Revision number to retrieve."""


class PartGetRevisionCreatedByUserTypedDict(TypedDict):
    r"""User who created the revision."""

    name: Nullable[str]
    r"""Name of the user who created the revision."""
    image: Nullable[str]
    r"""Profile image URL of the user."""


class PartGetRevisionCreatedByUser(BaseModel):
    r"""User who created the revision."""

    name: Nullable[str]
    r"""Name of the user who created the revision."""

    image: Nullable[str]
    r"""Profile image URL of the user."""

    @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 PartGetRevisionCreatedByStationTypedDict(TypedDict):
    r"""Station that created the revision."""

    id: str
    r"""Unique identifier of the station."""
    name: str
    r"""Name of the station."""
    image: Nullable[str]
    r"""Station image URL."""


class PartGetRevisionCreatedByStation(BaseModel):
    r"""Station that created the revision."""

    id: str
    r"""Unique identifier of the station."""

    name: str
    r"""Name of the station."""

    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 PartGetRevisionPartTypedDict(TypedDict):
    r"""Part associated with this revision."""

    id: str
    r"""Unique identifier of the part."""
    number: str
    r"""Part number."""
    name: str
    r"""Name of the part."""


class PartGetRevisionPart(BaseModel):
    r"""Part associated with this revision."""

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

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

    name: str
    r"""Name of the part."""


class PartGetRevisionUnitTypedDict(TypedDict):
    id: str
    r"""Unique identifier of the unit."""
    serial_number: str
    r"""Serial number of the unit."""


class PartGetRevisionUnit(BaseModel):
    id: str
    r"""Unique identifier of the unit."""

    serial_number: str
    r"""Serial number of the unit."""


class PartGetRevisionResponseTypedDict(TypedDict):
    r"""Revision retrieved successfully"""

    id: str
    r"""Unique identifier of the revision."""
    number: str
    r"""Revision number."""
    created_at: Nullable[datetime]
    r"""ISO 8601 timestamp when the revision was created."""
    created_by_user: Nullable[PartGetRevisionCreatedByUserTypedDict]
    r"""User who created the revision."""
    created_by_station: Nullable[PartGetRevisionCreatedByStationTypedDict]
    r"""Station that created the revision."""
    part: PartGetRevisionPartTypedDict
    r"""Part associated with this revision."""
    image: Nullable[str]
    r"""Image URL associated with the revision."""
    units: List[PartGetRevisionUnitTypedDict]
    r"""List of units created with this revision."""


class PartGetRevisionResponse(BaseModel):
    r"""Revision retrieved successfully"""

    id: str
    r"""Unique identifier of the revision."""

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

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

    created_by_user: Nullable[PartGetRevisionCreatedByUser]
    r"""User who created the revision."""

    created_by_station: Nullable[PartGetRevisionCreatedByStation]
    r"""Station that created the revision."""

    part: PartGetRevisionPart
    r"""Part associated with this revision."""

    image: Nullable[str]
    r"""Image URL associated with the revision."""

    units: List[PartGetRevisionUnit]
    r"""List of units created with this revision."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = [
            "created_at",
            "created_by_user",
            "created_by_station",
            "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
