"""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, QueryParamMetadata
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class StationListRequestTypedDict(TypedDict):
    limit: NotRequired[float]
    cursor: NotRequired[float]
    search_query: NotRequired[str]


class StationListRequest(BaseModel):
    limit: Annotated[
        Optional[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 50

    cursor: Annotated[
        Optional[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    search_query: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None


class StationListProcedureTypedDict(TypedDict):
    id: str
    r"""Procedure ID"""
    identifier: Nullable[str]
    r"""Procedure identifier"""
    name: str
    r"""Procedure name"""


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

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

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

    @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


class StationListDataTypedDict(TypedDict):
    id: str
    r"""Unique identifier of the station"""
    identifier: str
    r"""Station identifier"""
    name: str
    r"""Name of the station"""
    image: Nullable[str]
    r"""Direct image URL for the station"""
    procedures: List[StationListProcedureTypedDict]
    r"""Procedures linked to this station"""
    procedures_count: float
    r"""Total number of procedures linked to this station"""


class StationListData(BaseModel):
    id: str
    r"""Unique identifier of the station"""

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

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

    image: Nullable[str]
    r"""Direct image URL for the station"""

    procedures: List[StationListProcedure]
    r"""Procedures linked to this station"""

    procedures_count: float
    r"""Total number of procedures linked to this station"""

    @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 StationListMetaTypedDict(TypedDict):
    r"""Pagination metadata"""

    has_more: bool
    r"""Whether there are more results available for pagination"""
    next_cursor: Nullable[float]
    r"""Cursor value to fetch the next page of results. Use this value as the cursor parameter in the next request. Null if no more results available"""


class StationListMeta(BaseModel):
    r"""Pagination metadata"""

    has_more: bool
    r"""Whether there are more results available for pagination"""

    next_cursor: Nullable[float]
    r"""Cursor value to fetch the next page of results. Use this value as the cursor parameter in the next request. Null if no more results available"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = ["next_cursor"]
        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 StationListResponseTypedDict(TypedDict):
    r"""Stations retrieved successfully"""

    data: List[StationListDataTypedDict]
    r"""List of stations matching the search criteria"""
    meta: StationListMetaTypedDict
    r"""Pagination metadata"""


class StationListResponse(BaseModel):
    r"""Stations retrieved successfully"""

    data: List[StationListData]
    r"""List of stations matching the search criteria"""

    meta: StationListMeta
    r"""Pagination metadata"""
