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

from __future__ import annotations
from .accesslevel import AccessLevel
from .documentownership import DocumentOwnership
from .documenttrashstate import DocumentTrashState
from .listdocumentsresponse import ListDocumentsResponse, ListDocumentsResponseTypedDict
from .processingstatus import ProcessingStatus
from datetime import datetime
from factify.types import BaseModel, UNSET_SENTINEL
from factify.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Awaitable, Callable, Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class ListDocumentsRequestTypedDict(TypedDict):
    page_token: NotRequired[str]
    r"""Opaque pagination token from a previous response.
    Pass next_page_token or prev_page_token from a previous response to continue pagination.
    Empty or omitted for the first page.
    """
    page_size: NotRequired[int]
    r"""Maximum number of items to return per page (1-100). Default: 50."""
    created_after: NotRequired[datetime]
    r"""Return results after this timestamp (inclusive)."""
    created_before: NotRequired[datetime]
    r"""Return results before this timestamp (inclusive)."""
    created_by_id: NotRequired[List[str]]
    r"""Filter by creator ID(s) (user or bot). Returns documents matching ANY of the specified IDs.
    REST: ?created_by_id=user_01h2xcejqtf2nbrexx3vqjhp41 or ?created_by_id=user_xxx&created_by_id=bot_yyy
    """
    access_level: NotRequired[List[AccessLevel]]
    r"""Filter by access level(s). Returns documents matching ANY of the specified levels.
    REST: ?access_level=private or ?access_level=private&access_level=organization
    """
    processing_status: NotRequired[List[ProcessingStatus]]
    r"""Filter by processing status(es). Returns documents matching ANY of the specified statuses.
    REST: ?processing_status=ready or ?processing_status=processing&processing_status=ready
    """
    sort: NotRequired[str]
    r"""Sort field and direction. Prefix with `-` for descending order.
    Allowed values: created_at, updated_at, name, last_viewed_at, last_shared_at.
    Default (omitted): created_at descending.
    REST: ?sort=last_viewed_at or ?sort=-name
    """
    query: NotRequired[str]
    r"""Full-text search filter. Case-insensitive substring match on document name and description.
    REST: ?query=budget
    """
    ownership: NotRequired[List[DocumentOwnership]]
    r"""Ownership filter. Returns documents matching the specified ownership state.
    REST: ?ownership=owned or ?ownership=not_owned
    """
    trash_state: NotRequired[List[DocumentTrashState]]
    r"""Trash state filter. Returns documents matching the specified trash state.
    REST: ?trash_state=active or ?trash_state=trashed or ?trash_state=active&trash_state=trashed
    Default (omitted): active documents only.
    """
    organization_scope: NotRequired[bool]
    r"""Organization scope filter. When true, restrict to documents within the user's organization.
    REST: ?organization_scope=true
    """


class ListDocumentsRequest(BaseModel):
    page_token: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Opaque pagination token from a previous response.
    Pass next_page_token or prev_page_token from a previous response to continue pagination.
    Empty or omitted for the first page.
    """

    page_size: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Maximum number of items to return per page (1-100). Default: 50."""

    created_after: Annotated[
        Optional[datetime],
        pydantic.Field(alias="created.after"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Return results after this timestamp (inclusive)."""

    created_before: Annotated[
        Optional[datetime],
        pydantic.Field(alias="created.before"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Return results before this timestamp (inclusive)."""

    created_by_id: Annotated[
        Optional[List[str]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by creator ID(s) (user or bot). Returns documents matching ANY of the specified IDs.
    REST: ?created_by_id=user_01h2xcejqtf2nbrexx3vqjhp41 or ?created_by_id=user_xxx&created_by_id=bot_yyy
    """

    access_level: Annotated[
        Optional[List[AccessLevel]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by access level(s). Returns documents matching ANY of the specified levels.
    REST: ?access_level=private or ?access_level=private&access_level=organization
    """

    processing_status: Annotated[
        Optional[List[ProcessingStatus]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by processing status(es). Returns documents matching ANY of the specified statuses.
    REST: ?processing_status=ready or ?processing_status=processing&processing_status=ready
    """

    sort: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Sort field and direction. Prefix with `-` for descending order.
    Allowed values: created_at, updated_at, name, last_viewed_at, last_shared_at.
    Default (omitted): created_at descending.
    REST: ?sort=last_viewed_at or ?sort=-name
    """

    query: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Full-text search filter. Case-insensitive substring match on document name and description.
    REST: ?query=budget
    """

    ownership: Annotated[
        Optional[List[DocumentOwnership]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Ownership filter. Returns documents matching the specified ownership state.
    REST: ?ownership=owned or ?ownership=not_owned
    """

    trash_state: Annotated[
        Optional[List[DocumentTrashState]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Trash state filter. Returns documents matching the specified trash state.
    REST: ?trash_state=active or ?trash_state=trashed or ?trash_state=active&trash_state=trashed
    Default (omitted): active documents only.
    """

    organization_scope: Annotated[
        Optional[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Organization scope filter. When true, restrict to documents within the user's organization.
    REST: ?organization_scope=true
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "page_token",
                "page_size",
                "created.after",
                "created.before",
                "created_by_id",
                "access_level",
                "processing_status",
                "sort",
                "query",
                "ownership",
                "trash_state",
                "organization_scope",
            ]
        )
        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


class ListDocumentsResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: ListDocumentsResponseTypedDict


class ListDocumentsResponseResponse(BaseModel):
    next: Union[
        Callable[[], Optional[ListDocumentsResponseResponse]],
        Callable[[], Awaitable[Optional[ListDocumentsResponseResponse]]],
    ]

    headers: Dict[str, List[str]]

    result: ListDocumentsResponse
