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

from __future__ import annotations
import pydantic
from pydantic import model_serializer
from ship24.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class TimestampsTypedDict(TypedDict):
    r"""Date and time of the occurrence of each milestone of the shipment.

    [Date and time Format](https://docs.ship24.com/data-format#logistics-date-and-time)

    [List of Milestones](https://docs.ship24.com/status/#statusmilestone)
    """

    info_received_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `info_received` [milestone](https://docs.ship24.com/status/#statusmilestone)."""
    in_transit_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `in_transit` [milestone](https://docs.ship24.com/status/#statusmilestone)."""
    out_for_delivery_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `out_for_delivery` [milestone](https://docs.ship24.com/status/#statusmilestone)."""
    failed_attempt_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `failed_attempt` [milestone](https://docs.ship24.com/status/#statusmilestone)."""
    available_for_pickup_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `available_for_pickup` [milestone](https://docs.ship24.com/status/#statusmilestone)."""
    exception_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `exception` [milestone](https://docs.ship24.com/status/#statusmilestone)."""
    delivered_datetime: NotRequired[Nullable[str]]
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `delivered` [milestone](https://docs.ship24.com/status/#statusmilestone)."""


class Timestamps(BaseModel):
    r"""Date and time of the occurrence of each milestone of the shipment.

    [Date and time Format](https://docs.ship24.com/data-format#logistics-date-and-time)

    [List of Milestones](https://docs.ship24.com/status/#statusmilestone)
    """

    info_received_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="infoReceivedDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `info_received` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    in_transit_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="inTransitDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `in_transit` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    out_for_delivery_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="outForDeliveryDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `out_for_delivery` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    failed_attempt_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="failedAttemptDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `failed_attempt` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    available_for_pickup_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="availableForPickupDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `available_for_pickup` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    exception_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="exceptionDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `exception` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    delivered_datetime: Annotated[
        OptionalNullable[str], pydantic.Field(alias="deliveredDatetime")
    ] = UNSET
    r"""Occurrence [date and time](https://docs.ship24.com/data-format#logistics-date-and-time) of the first `delivered` [milestone](https://docs.ship24.com/status/#statusmilestone)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "infoReceivedDatetime",
            "inTransitDatetime",
            "outForDeliveryDatetime",
            "failedAttemptDatetime",
            "availableForPickupDatetime",
            "exceptionDatetime",
            "deliveredDatetime",
        ]
        nullable_fields = [
            "infoReceivedDatetime",
            "inTransitDatetime",
            "outForDeliveryDatetime",
            "failedAttemptDatetime",
            "availableForPickupDatetime",
            "exceptionDatetime",
            "deliveredDatetime",
        ]
        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 StatisticsTypedDict(TypedDict):
    timestamps: NotRequired[TimestampsTypedDict]
    r"""Date and time of the occurrence of each milestone of the shipment.

    [Date and time Format](https://docs.ship24.com/data-format#logistics-date-and-time)

    [List of Milestones](https://docs.ship24.com/status/#statusmilestone)
    """


class Statistics(BaseModel):
    timestamps: Optional[Timestamps] = None
    r"""Date and time of the occurrence of each milestone of the shipment.

    [Date and time Format](https://docs.ship24.com/data-format#logistics-date-and-time)

    [List of Milestones](https://docs.ship24.com/status/#statusmilestone)
    """
