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

from __future__ import annotations
from datetime import datetime
from mesa_sdk.types import BaseModel, Nullable, UNSET_SENTINEL
from mesa_sdk.utils import (
    FieldMetadata,
    PathParamMetadata,
    QueryParamMetadata,
    validate_const,
)
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Any, Awaitable, Callable, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class GetByOrgReposRequestTypedDict(TypedDict):
    org: str
    cursor: NotRequired[str]
    limit: NotRequired[int]


class GetByOrgReposRequest(BaseModel):
    org: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]

    cursor: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["cursor", "limit"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposInternalServerErrorErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposInternalServerErrorError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposConflictErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposConflictError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposNotAcceptableErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposNotAcceptableError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposNotFoundErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposNotFoundError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposForbiddenErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposForbiddenError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposUnauthorizedErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposUnauthorizedError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetByOrgReposBadRequestErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class GetByOrgReposBadRequestError(BaseModel):
    code: str

    message: str

    details: Optional[Dict[str, Any]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["details"])
        serialized = handler(self)
        m = {}

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

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

        return m


GetByOrgReposResolutionStrategy = Literal["none",]
r"""Conflict resolution strategy. \"none\" means sync will fail on conflicts."""


class GetByOrgReposAutosyncTypedDict(TypedDict):
    period: float
    r"""Polling period in seconds"""
    resolution_strategy: GetByOrgReposResolutionStrategy
    r"""Conflict resolution strategy. \"none\" means sync will fail on conflicts."""
    type: Literal["poll"]


class GetByOrgReposAutosync(BaseModel):
    period: float
    r"""Polling period in seconds"""

    resolution_strategy: GetByOrgReposResolutionStrategy
    r"""Conflict resolution strategy. \"none\" means sync will fail on conflicts."""

    type: Annotated[
        Annotated[Literal["poll"], AfterValidator(validate_const("poll"))],
        pydantic.Field(alias="type"),
    ] = "poll"


class GetByOrgReposUpstreamTypedDict(TypedDict):
    uri: str
    r"""URL of the upstream repository"""
    autosync: Nullable[GetByOrgReposAutosyncTypedDict]
    r"""Automatic sync configuration, if enabled"""
    last_sync_attempt: Nullable[datetime]
    r"""Timestamp of the last sync attempt"""
    last_sync_success: Nullable[datetime]
    r"""Timestamp of the last successful sync"""
    last_sync_error: Nullable[str]
    r"""Error message from the last failed sync attempt"""


class GetByOrgReposUpstream(BaseModel):
    uri: str
    r"""URL of the upstream repository"""

    autosync: Nullable[GetByOrgReposAutosync]
    r"""Automatic sync configuration, if enabled"""

    last_sync_attempt: Nullable[datetime]
    r"""Timestamp of the last sync attempt"""

    last_sync_success: Nullable[datetime]
    r"""Timestamp of the last successful sync"""

    last_sync_error: Nullable[str]
    r"""Error message from the last failed sync attempt"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                m[k] = val

        return m


class RepoTypedDict(TypedDict):
    id: str
    org: str
    name: str
    default_branch: str
    size_bytes: float
    last_push_at: Nullable[str]
    created_at: str
    upstream: Nullable[GetByOrgReposUpstreamTypedDict]
    r"""Optionally add an upstream repository. You can configure automatic syncing from the upstream repository."""


class Repo(BaseModel):
    id: str

    org: str

    name: str

    default_branch: str

    size_bytes: float

    last_push_at: Nullable[str]

    created_at: str

    upstream: Nullable[GetByOrgReposUpstream]
    r"""Optionally add an upstream repository. You can configure automatic syncing from the upstream repository."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                m[k] = val

        return m


class GetByOrgReposResponseBodyTypedDict(TypedDict):
    r"""Repository list"""

    next_cursor: Nullable[str]
    has_more: bool
    repos: List[RepoTypedDict]


class GetByOrgReposResponseBody(BaseModel):
    r"""Repository list"""

    next_cursor: Nullable[str]

    has_more: bool

    repos: List[Repo]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                m[k] = val

        return m


class GetByOrgReposResponseTypedDict(TypedDict):
    result: GetByOrgReposResponseBodyTypedDict


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

    result: GetByOrgReposResponseBody
