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

from __future__ import annotations
from .layoutcontrolsdto import LayoutControlsDto, LayoutControlsDtoTypedDict
from .resourceoriginenum import ResourceOriginEnum
from .resourcetypeenum import ResourceTypeEnum
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Any, Dict
from typing_extensions import Annotated, NotRequired, TypedDict


class UpdatedByTypedDict(TypedDict):
    r"""User who last updated the layout"""

    id: str
    r"""User ID"""
    first_name: NotRequired[Nullable[str]]
    r"""User first name"""
    last_name: NotRequired[Nullable[str]]
    r"""User last name"""
    external_id: NotRequired[Nullable[str]]
    r"""User external ID"""


class UpdatedBy(BaseModel):
    r"""User who last updated the layout"""

    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""User ID"""

    first_name: Annotated[OptionalNullable[str], pydantic.Field(alias="firstName")] = (
        UNSET
    )
    r"""User first name"""

    last_name: Annotated[OptionalNullable[str], pydantic.Field(alias="lastName")] = (
        UNSET
    )
    r"""User last name"""

    external_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="externalId")
    ] = UNSET
    r"""User external ID"""

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


class LayoutResponseDtoTypedDict(TypedDict):
    id: str
    r"""Unique internal identifier of the layout"""
    layout_id: str
    r"""Unique identifier for the layout"""
    slug: str
    r"""Slug of the layout"""
    name: str
    r"""Name of the layout"""
    is_default: bool
    r"""Whether the layout is the default layout"""
    is_translation_enabled: bool
    r"""Whether the layout translations are enabled"""
    updated_at: str
    r"""Last updated timestamp"""
    created_at: str
    r"""Creation timestamp"""
    origin: ResourceOriginEnum
    r"""Origin of the layout"""
    type: ResourceTypeEnum
    r"""Type of the layout"""
    controls: LayoutControlsDtoTypedDict
    r"""Controls metadata for the layout"""
    updated_by: NotRequired[Nullable[UpdatedByTypedDict]]
    r"""User who last updated the layout"""
    variables: NotRequired[Nullable[Dict[str, Any]]]
    r"""The variables JSON Schema for the layout"""


class LayoutResponseDto(BaseModel):
    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""Unique internal identifier of the layout"""

    layout_id: Annotated[str, pydantic.Field(alias="layoutId")]
    r"""Unique identifier for the layout"""

    slug: str
    r"""Slug of the layout"""

    name: str
    r"""Name of the layout"""

    is_default: Annotated[bool, pydantic.Field(alias="isDefault")]
    r"""Whether the layout is the default layout"""

    is_translation_enabled: Annotated[
        bool, pydantic.Field(alias="isTranslationEnabled")
    ]
    r"""Whether the layout translations are enabled"""

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

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

    origin: ResourceOriginEnum
    r"""Origin of the layout"""

    type: ResourceTypeEnum
    r"""Type of the layout"""

    controls: LayoutControlsDto
    r"""Controls metadata for the layout"""

    updated_by: Annotated[
        OptionalNullable[UpdatedBy], pydantic.Field(alias="updatedBy")
    ] = UNSET
    r"""User who last updated the layout"""

    variables: OptionalNullable[Dict[str, Any]] = UNSET
    r"""The variables JSON Schema for the layout"""

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