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

from __future__ import annotations
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, Literal
from typing_extensions import Annotated, TypedDict


class StationGetRequestTypedDict(TypedDict):
    id: str
    r"""Unique identifier of the station to retrieve"""


class StationGetRequest(BaseModel):
    id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Unique identifier of the station to retrieve"""


class StationGetProcedureTypedDict(TypedDict):
    id: str
    r"""Procedure ID"""
    identifier: Nullable[str]
    r"""Procedure identifier"""
    name: str
    r"""Procedure name"""
    runs_count: float
    r"""Number of runs created by this station in the last 7 days"""


class StationGetProcedure(BaseModel):
    id: str
    r"""Procedure ID"""

    identifier: Nullable[str]
    r"""Procedure identifier"""

    name: str
    r"""Procedure name"""

    runs_count: float
    r"""Number of runs created by this station in the last 7 days"""

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


ConnectionStatus = Literal["connected", "disconnected"]
r"""Current connection status of the station"""


class StationGetResponseTypedDict(TypedDict):
    r"""Station retrieved successfully"""

    id: str
    r"""Unique identifier of the station"""
    identifier: str
    r"""Station identifier"""
    name: str
    r"""Name of the station"""
    image: Nullable[str]
    r"""Image URL associated with the station"""
    api_key: Nullable[str]
    r"""API key for the station"""
    procedures: List[StationGetProcedureTypedDict]
    r"""Procedures linked to this station with recent run counts"""
    connection_status: Nullable[ConnectionStatus]
    r"""Current connection status of the station"""


class StationGetResponse(BaseModel):
    r"""Station retrieved successfully"""

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

    identifier: str
    r"""Station identifier"""

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

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

    api_key: Nullable[str]
    r"""API key for the station"""

    procedures: List[StationGetProcedure]
    r"""Procedures linked to this station with recent run counts"""

    connection_status: Nullable[ConnectionStatus]
    r"""Current connection status of the station"""

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