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

from __future__ import annotations
from datetime import datetime
import pydantic
from pydantic import model_serializer
from squadcast_sdk.types import BaseModel, Nullable, UNSET_SENTINEL
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class V4StatusPagesMaintenancesGetMaintenanceByIDResponseTypedDict(TypedDict):
    id: int
    page_id: int
    title: str
    note: str
    start_time: datetime
    end_time: datetime
    created_at: datetime
    updated_at: datetime
    deleted_at: Nullable[datetime]
    component_id_list: NotRequired[List[int]]


class V4StatusPagesMaintenancesGetMaintenanceByIDResponse(BaseModel):
    id: Annotated[int, pydantic.Field(alias="ID")]

    page_id: Annotated[int, pydantic.Field(alias="PageID")]

    title: Annotated[str, pydantic.Field(alias="Title")]

    note: Annotated[str, pydantic.Field(alias="Note")]

    start_time: Annotated[datetime, pydantic.Field(alias="StartTime")]

    end_time: Annotated[datetime, pydantic.Field(alias="EndTime")]

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]

    deleted_at: Annotated[Nullable[datetime], pydantic.Field(alias="deletedAt")]

    component_id_list: Annotated[
        Optional[List[int]], pydantic.Field(alias="ComponentIDList")
    ] = None

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