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

from __future__ import annotations
from .recipient import Recipient, RecipientTypedDict
from .sender import Sender, SenderTypedDict
from datetime import datetime
from postivo_client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ShipmentPriceStatusTypedDict(TypedDict):
    r"""Shipment processing status."""

    error: NotRequired[bool]
    r"""Indicates whether an error occurred during processing."""
    code: NotRequired[str]
    r"""Status code."""
    description: NotRequired[str]
    r"""Status description."""
    date_: NotRequired[datetime]
    r"""Status timestamp (UTC)."""


class ShipmentPriceStatus(BaseModel):
    r"""Shipment processing status."""

    error: Optional[bool] = None
    r"""Indicates whether an error occurred during processing."""

    code: Optional[str] = None
    r"""Status code."""

    description: Optional[str] = None
    r"""Status description."""

    date_: Annotated[Optional[datetime], pydantic.Field(alias="date")] = None
    r"""Status timestamp (UTC)."""


class ShipmentPriceCarrierTypedDict(TypedDict):
    r"""Postal operator that will handle the shipment."""

    id: NotRequired[Nullable[int]]
    r"""Postal operator ID."""
    name: NotRequired[Nullable[str]]
    r"""Postal operator name."""


class ShipmentPriceCarrier(BaseModel):
    r"""Postal operator that will handle the shipment."""

    id: OptionalNullable[int] = UNSET
    r"""Postal operator ID."""

    name: OptionalNullable[str] = UNSET
    r"""Postal operator name."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["id", "name"]
        nullable_fields = ["id", "name"]
        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 ShipmentPriceServiceTypedDict(TypedDict):
    r"""Service (shipment type) selected."""

    id: NotRequired[Nullable[int]]
    r"""Service type ID (shipment/letter type)."""
    name: NotRequired[Nullable[str]]
    r"""Service type name (shipment/letter type)."""


class ShipmentPriceService(BaseModel):
    r"""Service (shipment type) selected."""

    id: OptionalNullable[int] = UNSET
    r"""Service type ID (shipment/letter type)."""

    name: OptionalNullable[str] = UNSET
    r"""Service type name (shipment/letter type)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["id", "name"]
        nullable_fields = ["id", "name"]
        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 ShipmentPriceTypedDict(TypedDict):
    r"""Pricing details for a single shipment"""

    recipient: NotRequired[RecipientTypedDict]
    r"""Recipient data for a shipment, including full postal address."""
    sender: NotRequired[SenderTypedDict]
    r"""Sender data for the shipment."""
    status: NotRequired[ShipmentPriceStatusTypedDict]
    r"""Shipment processing status."""
    carrier: NotRequired[ShipmentPriceCarrierTypedDict]
    r"""Postal operator that will handle the shipment."""
    service: NotRequired[ShipmentPriceServiceTypedDict]
    r"""Service (shipment type) selected."""
    page_number: NotRequired[int]
    r"""Total number of pages across all documents in the shipment."""
    price: NotRequired[float]
    r"""Shipment price (PLN)."""


class ShipmentPrice(BaseModel):
    r"""Pricing details for a single shipment"""

    recipient: Optional[Recipient] = None
    r"""Recipient data for a shipment, including full postal address."""

    sender: Optional[Sender] = None
    r"""Sender data for the shipment."""

    status: Optional[ShipmentPriceStatus] = None
    r"""Shipment processing status."""

    carrier: Optional[ShipmentPriceCarrier] = None
    r"""Postal operator that will handle the shipment."""

    service: Optional[ShipmentPriceService] = None
    r"""Service (shipment type) selected."""

    page_number: Optional[int] = None
    r"""Total number of pages across all documents in the shipment."""

    price: Optional[float] = None
    r"""Shipment price (PLN)."""
