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


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


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

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


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


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


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


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


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


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


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


class GetByOrgByRepoSyncBadRequestError(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 StatusErrorTypedDict(TypedDict):
    r"""The last sync failed with an error."""

    message: str
    r"""Error message from the last failed sync attempt"""
    type: Literal["error"]


class StatusError(BaseModel):
    r"""The last sync failed with an error."""

    message: str
    r"""Error message from the last failed sync attempt"""

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


class StatusOkTypedDict(TypedDict):
    r"""The last sync was successful."""

    type: Literal["ok"]


class StatusOk(BaseModel):
    r"""The last sync was successful."""

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


StatusTypedDict = TypeAliasType(
    "StatusTypedDict", Union[StatusOkTypedDict, StatusErrorTypedDict]
)
r"""What the status of the last sync was."""


Status = Annotated[Union[StatusOk, StatusError], Field(discriminator="type")]
r"""What the status of the last sync was."""


class GetByOrgByRepoSyncResponseTypedDict(TypedDict):
    r"""Sync status"""

    last_sync_attempt: Nullable[datetime]
    r"""Timestamp of the last sync attempt"""
    last_sync_success: Nullable[datetime]
    r"""Timestamp of the last successful sync"""
    status: StatusTypedDict
    r"""What the status of the last sync was."""


class GetByOrgByRepoSyncResponse(BaseModel):
    r"""Sync status"""

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

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

    status: Status
    r"""What the status of the last sync was."""

    @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
