"""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.types import BaseModel, UNSET_SENTINEL
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class V4StatusPagesMaintenancesMaintenanceComponentTypedDict(TypedDict):
    id: NotRequired[int]
    name: NotRequired[str]
    group_name: NotRequired[str]


class V4StatusPagesMaintenancesMaintenanceComponent(BaseModel):
    id: Optional[int] = None

    name: Optional[str] = None

    group_name: Annotated[Optional[str], pydantic.Field(alias="groupName")] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["id", "name", "groupName"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class V4StatusPagesMaintenancesMaintenanceTypedDict(TypedDict):
    id: NotRequired[int]
    title: NotRequired[str]
    page_id: NotRequired[int]
    note: NotRequired[str]
    components: NotRequired[
        List[V4StatusPagesMaintenancesMaintenanceComponentTypedDict]
    ]
    start_time: NotRequired[datetime]
    end_time: NotRequired[datetime]
    maintenance_state: NotRequired[str]


class V4StatusPagesMaintenancesMaintenance(BaseModel):
    id: Optional[int] = None

    title: Optional[str] = None

    page_id: Annotated[Optional[int], pydantic.Field(alias="pageID")] = None

    note: Optional[str] = None

    components: Optional[List[V4StatusPagesMaintenancesMaintenanceComponent]] = None

    start_time: Annotated[Optional[datetime], pydantic.Field(alias="startTime")] = None

    end_time: Annotated[Optional[datetime], pydantic.Field(alias="endTime")] = None

    maintenance_state: Annotated[
        Optional[str], pydantic.Field(alias="maintenanceState")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "title",
                "pageID",
                "note",
                "components",
                "startTime",
                "endTime",
                "maintenanceState",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    V4StatusPagesMaintenancesMaintenanceComponent.model_rebuild()
except NameError:
    pass
try:
    V4StatusPagesMaintenancesMaintenance.model_rebuild()
except NameError:
    pass
