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


class GetByOrgByRepoRequestTypedDict(TypedDict):
    org: str
    repo: str


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

    repo: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]


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


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


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


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


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


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


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


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


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


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


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

    resolution_strategy: GetByOrgByRepoResolutionStrategy
    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 GetByOrgByRepoUpstreamTypedDict(TypedDict):
    uri: str
    r"""URL of the upstream repository"""
    autosync: Nullable[GetByOrgByRepoAutosyncTypedDict]
    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 GetByOrgByRepoUpstream(BaseModel):
    uri: str
    r"""URL of the upstream repository"""

    autosync: Nullable[GetByOrgByRepoAutosync]
    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 GetByOrgByRepoResponseTypedDict(TypedDict):
    r"""Repository"""

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


class GetByOrgByRepoResponse(BaseModel):
    r"""Repository"""

    id: str

    org: str

    name: str

    default_branch: str

    size_bytes: float

    last_push_at: Nullable[str]

    created_at: str

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