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

from __future__ import annotations
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from syllable_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
from typing_extensions import Annotated, NotRequired, TypedDict


class RolesDeleteRequestTypedDict(TypedDict):
    role_id: int
    r"""The ID of the role to delete"""
    reason: str
    r"""The reason for deleting the role"""
    new_role_id: NotRequired[Nullable[int]]
    r"""Users with the deleted role will be reassigned to the new role, if a new role ID is provided"""


class RolesDeleteRequest(BaseModel):
    role_id: Annotated[
        int, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The ID of the role to delete"""

    reason: Annotated[
        str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]
    r"""The reason for deleting the role"""

    new_role_id: Annotated[
        OptionalNullable[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Users with the deleted role will be reassigned to the new role, if a new role ID is provided"""

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