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

from __future__ import annotations
from .organizationinvitestatus import OrganizationInviteStatus
from .user import User, UserTypedDict
from datetime import datetime
from factify.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class OrganizationInviteTypedDict(TypedDict):
    r"""OrganizationInvite represents an invitation to join an organization.
    accepted_fields_consistency // accepted_at and accepted_by must both be set or both be unset

    """

    created_at: datetime
    r"""When the invitation was created."""
    email: str
    r"""Email address of the recipient."""
    expires_at: datetime
    r"""When the invitation expires."""
    id: str
    r"""Unique identifier for the invitation."""
    organization_id: str
    r"""Organization the invitation is for."""
    sender: UserTypedDict
    r"""User represents a human user account.
    Returned by GetUser (endpoint deferred).
    """
    status: OrganizationInviteStatus
    accepted_at: NotRequired[datetime]
    r"""When the invitation was accepted (if accepted)."""
    accepted_by: NotRequired[UserTypedDict]
    r"""User represents a human user account.
    Returned by GetUser (endpoint deferred).
    """
    message: NotRequired[Nullable[str]]
    r"""Custom message from sender to recipient (if provided).
    Max 2000 bytes to support ~500 multibyte characters.
    """


class OrganizationInvite(BaseModel):
    r"""OrganizationInvite represents an invitation to join an organization.
    accepted_fields_consistency // accepted_at and accepted_by must both be set or both be unset

    """

    created_at: datetime
    r"""When the invitation was created."""

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

    expires_at: datetime
    r"""When the invitation expires."""

    id: str
    r"""Unique identifier for the invitation."""

    organization_id: str
    r"""Organization the invitation is for."""

    sender: User
    r"""User represents a human user account.
    Returned by GetUser (endpoint deferred).
    """

    status: OrganizationInviteStatus

    accepted_at: Optional[datetime] = None
    r"""When the invitation was accepted (if accepted)."""

    accepted_by: Optional[User] = None
    r"""User represents a human user account.
    Returned by GetUser (endpoint deferred).
    """

    message: OptionalNullable[str] = UNSET
    r"""Custom message from sender to recipient (if provided).
    Max 2000 bytes to support ~500 multibyte characters.
    """

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