"""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 syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing_extensions import Annotated, NotRequired, TypedDict


class IncidentCreateRequestTypedDict(TypedDict):
    r"""Request model to create a service incident."""

    description: str
    r"""Description of the service incident"""
    start_datetime: datetime
    r"""Start time of the incident"""
    resolution_datetime: datetime
    r"""Resolution time of the incident"""
    impact_category: str
    r"""Category of the impact"""
    sessions_impacted: int
    r"""Number of sessions impacted"""
    markdown: str
    r"""Detailed markdown description of the incident"""
    organization_id: NotRequired[Nullable[int]]
    r"""The ID of the organization"""
    sub_organization_id: NotRequired[Nullable[int]]
    r"""The ID of the sub-organization"""
    sub_organization: NotRequired[Nullable[str]]
    r"""The name of the sub-organization (DEPRECATED)"""


class IncidentCreateRequest(BaseModel):
    r"""Request model to create a service incident."""

    description: str
    r"""Description of the service incident"""

    start_datetime: datetime
    r"""Start time of the incident"""

    resolution_datetime: datetime
    r"""Resolution time of the incident"""

    impact_category: str
    r"""Category of the impact"""

    sessions_impacted: int
    r"""Number of sessions impacted"""

    markdown: str
    r"""Detailed markdown description of the incident"""

    organization_id: OptionalNullable[int] = UNSET
    r"""The ID of the organization"""

    sub_organization_id: OptionalNullable[int] = UNSET
    r"""The ID of the sub-organization"""

    sub_organization: Annotated[
        OptionalNullable[str],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ] = UNSET
    r"""The name of the sub-organization (DEPRECATED)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["organization_id", "sub_organization_id", "sub_organization"]
        )
        nullable_fields = set(
            ["organization_id", "sub_organization_id", "sub_organization"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
