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

from __future__ import annotations
from .createorganizationinviteresponse import (
    CreateOrganizationInviteResponse,
    CreateOrganizationInviteResponseTypedDict,
)
from factify.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from factify.utils import FieldMetadata, PathParamMetadata, RequestMetadata
from pydantic import model_serializer
from typing import Dict, List
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateOrganizationInviteCreateOrganizationInviteRequestTypedDict(TypedDict):
    r"""CreateOrganizationInviteRequest contains the data needed to create an invitation."""

    email: str
    r"""Email address of the recipient."""
    idempotency_key: NotRequired[Nullable[str]]
    r"""Reserved for future use. Currently, idempotency is based on email matching:
    if a PENDING invitation exists for the same email in this organization,
    that invitation is resent rather than creating a duplicate.
    """
    message: NotRequired[Nullable[str]]
    r"""Optional custom message from the sender (max 2000 bytes to support ~500 multibyte characters)."""


class CreateOrganizationInviteCreateOrganizationInviteRequest(BaseModel):
    r"""CreateOrganizationInviteRequest contains the data needed to create an invitation."""

    email: str
    r"""Email address of the recipient."""

    idempotency_key: OptionalNullable[str] = UNSET
    r"""Reserved for future use. Currently, idempotency is based on email matching:
    if a PENDING invitation exists for the same email in this organization,
    that invitation is resent rather than creating a duplicate.
    """

    message: OptionalNullable[str] = UNSET
    r"""Optional custom message from the sender (max 2000 bytes to support ~500 multibyte characters)."""

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


class CreateOrganizationInviteRequestTypedDict(TypedDict):
    organization_id: str
    r"""Organization to invite the user to.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """
    body: CreateOrganizationInviteCreateOrganizationInviteRequestTypedDict


class CreateOrganizationInviteRequest(BaseModel):
    organization_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Organization to invite the user to.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """

    body: Annotated[
        CreateOrganizationInviteCreateOrganizationInviteRequest,
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ]


class CreateOrganizationInviteResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: CreateOrganizationInviteResponseTypedDict


class CreateOrganizationInviteResponseResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: CreateOrganizationInviteResponse
