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

from __future__ import annotations
from .accessgrantresult import AccessGrantResult, AccessGrantResultTypedDict
from factify.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class GrantDocumentAccessResponseTypedDict(TypedDict):
    r"""GrantDocumentAccessResponse contains the results of granting access."""

    document_id: NotRequired[str]
    r"""Document ID."""
    failed: NotRequired[int]
    r"""Number of failed grants."""
    results: NotRequired[List[AccessGrantResultTypedDict]]
    r"""Results for each recipient."""
    successful: NotRequired[int]
    r"""Number of successful grants."""
    total: NotRequired[int]
    r"""Total number of recipients processed."""


class GrantDocumentAccessResponse(BaseModel):
    r"""GrantDocumentAccessResponse contains the results of granting access."""

    document_id: Optional[str] = None
    r"""Document ID."""

    failed: Optional[int] = None
    r"""Number of failed grants."""

    results: Optional[List[AccessGrantResult]] = None
    r"""Results for each recipient."""

    successful: Optional[int] = None
    r"""Number of successful grants."""

    total: Optional[int] = None
    r"""Total number of recipients processed."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["document_id", "failed", "results", "successful", "total"]
        )
        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))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
