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

from __future__ import annotations
from .listorganizationinvitesresponse import (
    ListOrganizationInvitesResponse,
    ListOrganizationInvitesResponseTypedDict,
)
from .organizationinvitestatus import OrganizationInviteStatus
from datetime import datetime
from factify.types import BaseModel, UNSET_SENTINEL
from factify.utils import FieldMetadata, PathParamMetadata, 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 ListOrganizationInvitesRequestTypedDict(TypedDict):
    organization_id: str
    r"""Organization to list invitations for.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """
    status: NotRequired[List[OrganizationInviteStatus]]
    r"""Filter by invitation status.
    If empty, returns all invitations.
    REST: ?status=pending or ?status=pending&status=expired
    """
    page_token: NotRequired[str]
    r"""Opaque pagination token from a previous response."""
    page_size: NotRequired[int]
    r"""Maximum number of items to return per page (1-100). Default: 50."""
    email_contains: NotRequired[str]
    r"""Case-insensitive substring match.
    REST: ?field.contains=value
    """
    email_exact: NotRequired[str]
    r"""Exact match (case-sensitive).
    REST: ?field.exact=value
    """
    sender_id: NotRequired[str]
    r"""Filter by sender. Only returns invitations sent by this user.
    REST: ?sender_id=user_01h2xcejqtf2nbrexx3vqjhp41
    Pattern: user_[0-9a-hjkmnp-tv-z]{26}
    """
    created_after: NotRequired[datetime]
    r"""Return results after this timestamp (inclusive)."""
    created_before: NotRequired[datetime]
    r"""Return results before this timestamp (inclusive)."""


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

    status: Annotated[
        Optional[List[OrganizationInviteStatus]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by invitation status.
    If empty, returns all invitations.
    REST: ?status=pending or ?status=pending&status=expired
    """

    page_token: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Opaque pagination token from a previous response."""

    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."""

    email_contains: Annotated[
        Optional[str],
        pydantic.Field(alias="email.contains"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Case-insensitive substring match.
    REST: ?field.contains=value
    """

    email_exact: Annotated[
        Optional[str],
        pydantic.Field(alias="email.exact"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Exact match (case-sensitive).
    REST: ?field.exact=value
    """

    sender_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by sender. Only returns invitations sent by this user.
    REST: ?sender_id=user_01h2xcejqtf2nbrexx3vqjhp41
    Pattern: user_[0-9a-hjkmnp-tv-z]{26}
    """

    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)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "status",
                "page_token",
                "page_size",
                "email.contains",
                "email.exact",
                "sender_id",
                "created.after",
                "created.before",
            ]
        )
        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 ListOrganizationInvitesResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: ListOrganizationInvitesResponseTypedDict


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

    headers: Dict[str, List[str]]

    result: ListOrganizationInvitesResponse
