"""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,
    RequestMetadata,
    validate_const,
)
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Any, Dict, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


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


class PostByOrgReposAutosyncPollRequestTypedDict(TypedDict):
    period: int
    r"""Polling period in seconds (60s to 24.8d)"""
    type: Literal["poll"]
    resolution_strategy: NotRequired[PostByOrgReposResolutionStrategyRequest]
    r"""Conflict resolution strategy. \"none\" means sync will fail on conflicts."""


class PostByOrgReposAutosyncPollRequest(BaseModel):
    period: int
    r"""Polling period in seconds (60s to 24.8d)"""

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

    resolution_strategy: Optional[PostByOrgReposResolutionStrategyRequest] = "none"
    r"""Conflict resolution strategy. \"none\" means sync will fail on conflicts."""

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


PostByOrgReposAutosyncUnionTypedDict = PostByOrgReposAutosyncPollRequestTypedDict
r"""Optionally enable automatic sync from the upstream repository"""


PostByOrgReposAutosyncUnion = PostByOrgReposAutosyncPollRequest
r"""Optionally enable automatic sync from the upstream repository"""


class PostByOrgReposUpstreamRequestTypedDict(TypedDict):
    uri: str
    r"""URL of the upstream repository"""
    autosync: NotRequired[PostByOrgReposAutosyncUnionTypedDict]
    r"""Optionally enable automatic sync from the upstream repository"""


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

    autosync: Optional[PostByOrgReposAutosyncUnion] = None
    r"""Optionally enable automatic sync from the upstream repository"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["autosync"])
        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 PostByOrgReposRequestBodyTypedDict(TypedDict):
    name: str
    default_branch: NotRequired[str]
    upstream: NotRequired[PostByOrgReposUpstreamRequestTypedDict]


class PostByOrgReposRequestBody(BaseModel):
    name: str

    default_branch: Optional[str] = "main"

    upstream: Optional[PostByOrgReposUpstreamRequest] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["default_branch", "upstream"])
        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 PostByOrgReposRequestTypedDict(TypedDict):
    org: str
    body: NotRequired[PostByOrgReposRequestBodyTypedDict]


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

    body: Annotated[
        Optional[PostByOrgReposRequestBody],
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["body"])
        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 PostByOrgReposInternalServerErrorErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposInternalServerErrorError(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 PostByOrgReposConflictErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposConflictError(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 PostByOrgReposNotAcceptableErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposNotAcceptableError(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 PostByOrgReposNotFoundErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposNotFoundError(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 PostByOrgReposForbiddenErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposForbiddenError(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 PostByOrgReposUnauthorizedErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposUnauthorizedError(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 PostByOrgReposBadRequestErrorTypedDict(TypedDict):
    code: str
    message: str
    details: NotRequired[Dict[str, Any]]


class PostByOrgReposBadRequestError(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


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


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


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

    resolution_strategy: PostByOrgReposResolutionStrategyResponse
    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 PostByOrgReposUpstreamResponseTypedDict(TypedDict):
    uri: str
    r"""URL of the upstream repository"""
    autosync: Nullable[PostByOrgReposAutosyncResponseTypedDict]
    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 PostByOrgReposUpstreamResponse(BaseModel):
    uri: str
    r"""URL of the upstream repository"""

    autosync: Nullable[PostByOrgReposAutosyncResponse]
    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 PostByOrgReposResponseTypedDict(TypedDict):
    r"""Repository created"""

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


class PostByOrgReposResponse(BaseModel):
    r"""Repository created"""

    id: str

    org: str

    name: str

    default_branch: str

    size_bytes: float

    last_push_at: Nullable[str]

    created_at: str

    upstream: Nullable[PostByOrgReposUpstreamResponse]
    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
