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

from __future__ import annotations
from .grantdocumentaccessresponse import (
    GrantDocumentAccessResponse,
    GrantDocumentAccessResponseTypedDict,
)
from .recipientgrant import RecipientGrant, RecipientGrantTypedDict
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, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class GrantDocumentAccessGrantDocumentAccessRequestTypedDict(TypedDict):
    r"""GrantDocumentAccessRequest grants access to one or more recipients."""

    custom_message: NotRequired[Nullable[str]]
    r"""Custom message to include in the notification email."""
    recipients: NotRequired[List[RecipientGrantTypedDict]]
    r"""Recipients to grant access to (1-50)."""
    should_send_notification: NotRequired[Nullable[bool]]
    r"""Whether to send email notifications."""


class GrantDocumentAccessGrantDocumentAccessRequest(BaseModel):
    r"""GrantDocumentAccessRequest grants access to one or more recipients."""

    custom_message: OptionalNullable[str] = UNSET
    r"""Custom message to include in the notification email."""

    recipients: Optional[List[RecipientGrant]] = None
    r"""Recipients to grant access to (1-50)."""

    should_send_notification: OptionalNullable[bool] = UNSET
    r"""Whether to send email notifications."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["custom_message", "recipients", "should_send_notification"]
        )
        nullable_fields = set(["custom_message", "should_send_notification"])
        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 GrantDocumentAccessRequestTypedDict(TypedDict):
    document_id: str
    r"""Document ID."""
    body: GrantDocumentAccessGrantDocumentAccessRequestTypedDict


class GrantDocumentAccessRequest(BaseModel):
    document_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Document ID."""

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


class GrantDocumentAccessResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: GrantDocumentAccessResponseTypedDict


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

    result: GrantDocumentAccessResponse
