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

from __future__ import annotations
from .articlevisibility import ArticleVisibility
from .listresource_article_ import ListResourceArticle, ListResourceArticleTypedDict
from polar_sdk.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from polar_sdk.utils import FieldMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Callable, List, Optional, TypedDict, Union
from typing_extensions import Annotated, NotRequired


ArticlesListQueryParamOrganizationIDFilterTypedDict = Union[str, List[str]]
r"""Filter by organization ID."""


ArticlesListQueryParamOrganizationIDFilter = Union[str, List[str]]
r"""Filter by organization ID."""


ArticleVisibilityFilterTypedDict = Union[ArticleVisibility, List[ArticleVisibility]]
r"""Filter by visibility."""


ArticleVisibilityFilter = Union[ArticleVisibility, List[ArticleVisibility]]
r"""Filter by visibility."""


class ArticlesListRequestTypedDict(TypedDict):
    organization_id: NotRequired[Nullable[ArticlesListQueryParamOrganizationIDFilterTypedDict]]
    r"""Filter by organization ID."""
    slug: NotRequired[Nullable[str]]
    r"""Filter by slug."""
    visibility: NotRequired[Nullable[ArticleVisibilityFilterTypedDict]]
    r"""Filter by visibility."""
    is_subscribed: NotRequired[Nullable[bool]]
    r"""Filter by subscription status."""
    is_published: NotRequired[Nullable[bool]]
    r"""Filter by published status."""
    is_pinned: NotRequired[Nullable[bool]]
    r"""Filter by pinned status."""
    page: NotRequired[int]
    r"""Page number, defaults to 1."""
    limit: NotRequired[int]
    r"""Size of a page, defaults to 10. Maximum is 100."""
    

class ArticlesListRequest(BaseModel):
    organization_id: Annotated[OptionalNullable[ArticlesListQueryParamOrganizationIDFilter], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""Filter by organization ID."""
    slug: Annotated[OptionalNullable[str], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""Filter by slug."""
    visibility: Annotated[OptionalNullable[ArticleVisibilityFilter], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""Filter by visibility."""
    is_subscribed: Annotated[OptionalNullable[bool], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""Filter by subscription status."""
    is_published: Annotated[OptionalNullable[bool], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""Filter by published status."""
    is_pinned: Annotated[OptionalNullable[bool], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""Filter by pinned status."""
    page: Annotated[Optional[int], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = 1
    r"""Page number, defaults to 1."""
    limit: Annotated[Optional[int], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = 10
    r"""Size of a page, defaults to 10. Maximum is 100."""
    
    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["organization_id", "slug", "visibility", "is_subscribed", "is_published", "is_pinned", "page", "limit"]
        nullable_fields = ["organization_id", "slug", "visibility", "is_subscribed", "is_published", "is_pinned"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (self.__pydantic_fields_set__.intersection({n}) or k in null_default_fields) # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
        

class ArticlesListResponseTypedDict(TypedDict):
    result: ListResourceArticleTypedDict
    

class ArticlesListResponse(BaseModel):
    next: Callable[[], Optional[ArticlesListResponse]]
    
    result: ListResourceArticle
    
