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

from __future__ import annotations
from .v4_participantgroup import V4ParticipantGroup, V4ParticipantGroupTypedDict
from .v4_shifttimeslot import V4ShiftTimeSlot, V4ShiftTimeSlotTypedDict
import pydantic
from pydantic import model_serializer
from squadcast_sdk.types import BaseModel, UNSET_SENTINEL
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class V4RotationResponseTypedDict(TypedDict):
    id: int
    name: str
    schedule_id: int
    color: str
    start_date: str
    period: str
    change_participants_frequency: int
    change_participants_unit: str
    created_at: str
    updated_at: str
    custom_period_frequency: NotRequired[int]
    custom_period_unit: NotRequired[str]
    shift_time_slots: NotRequired[List[V4ShiftTimeSlotTypedDict]]
    end_date: NotRequired[str]
    ends_after_iterations: NotRequired[int]
    rotation_participants: NotRequired[List[V4ParticipantGroupTypedDict]]


class V4RotationResponse(BaseModel):
    id: int

    name: str

    schedule_id: Annotated[int, pydantic.Field(alias="scheduleID")]

    color: str

    start_date: Annotated[str, pydantic.Field(alias="startDate")]

    period: str

    change_participants_frequency: Annotated[
        int, pydantic.Field(alias="changeParticipantsFrequency")
    ]

    change_participants_unit: Annotated[
        str, pydantic.Field(alias="changeParticipantsUnit")
    ]

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

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

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

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

    shift_time_slots: Annotated[
        Optional[List[V4ShiftTimeSlot]], pydantic.Field(alias="shiftTimeSlots")
    ] = None

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

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

    rotation_participants: Annotated[
        Optional[List[V4ParticipantGroup]], pydantic.Field(alias="rotationParticipants")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "customPeriodFrequency",
                "customPeriodUnit",
                "shiftTimeSlots",
                "endDate",
                "endsAfterIterations",
                "rotationParticipants",
            ]
        )
        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:
    V4RotationResponse.model_rebuild()
except NameError:
    pass
