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

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


class GetByOrgByRepoContentRequestTypedDict(TypedDict):
    org: str
    repo: str
    ref: NotRequired[str]
    path: NotRequired[str]
    depth: NotRequired[int]


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

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

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

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

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

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


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


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


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


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


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


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


class GetByOrgByRepoContentBadRequestError(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 EntryDirTypedDict(TypedDict):
    name: str
    path: str
    sha: str
    type: Literal["dir"]


class EntryDir(BaseModel):
    name: str

    path: str

    sha: str

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


class EntrySymlinkTypedDict(TypedDict):
    name: str
    path: str
    sha: str
    size: float
    executable: bool
    last_commit_at: Nullable[datetime]
    type: Literal["symlink"]


class EntrySymlink(BaseModel):
    name: str

    path: str

    sha: str

    size: float

    executable: bool

    last_commit_at: Nullable[datetime]

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

    @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 EntryFileTypedDict(TypedDict):
    name: str
    path: str
    sha: str
    size: float
    executable: bool
    last_commit_at: Nullable[datetime]
    type: Literal["file"]


class EntryFile(BaseModel):
    name: str

    path: str

    sha: str

    size: float

    executable: bool

    last_commit_at: Nullable[datetime]

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

    @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


EntryTypedDict = TypeAliasType(
    "EntryTypedDict",
    Union[EntryDirTypedDict, EntryFileTypedDict, EntrySymlinkTypedDict],
)


Entry = Annotated[Union[EntryFile, EntrySymlink, EntryDir], Field(discriminator="type")]


class DirTypedDict(TypedDict):
    name: str
    path: str
    sha: str
    child_count: int
    entries: List[EntryTypedDict]
    type: Literal["dir"]


class Dir(BaseModel):
    name: str

    path: str

    sha: str

    child_count: int

    entries: List[Entry]

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


class SymlinkBase64TypedDict(TypedDict):
    name: str
    path: str
    sha: str
    size: float
    content: str
    executable: bool
    last_commit_at: Nullable[datetime]
    type: Literal["symlink"]
    encoding: Literal["base64"]


class SymlinkBase64(BaseModel):
    name: str

    path: str

    sha: str

    size: float

    content: str

    executable: bool

    last_commit_at: Nullable[datetime]

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

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

    @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 FileBase64TypedDict(TypedDict):
    name: str
    path: str
    sha: str
    size: float
    content: str
    executable: bool
    last_commit_at: Nullable[datetime]
    type: Literal["file"]
    encoding: Literal["base64"]


class FileBase64(BaseModel):
    name: str

    path: str

    sha: str

    size: float

    content: str

    executable: bool

    last_commit_at: Nullable[datetime]

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

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

    @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


GetByOrgByRepoContentResponseBodyTypedDict = TypeAliasType(
    "GetByOrgByRepoContentResponseBodyTypedDict",
    Union[DirTypedDict, FileBase64TypedDict, SymlinkBase64TypedDict],
)
r"""Content response"""


GetByOrgByRepoContentResponseBody = Annotated[
    Union[FileBase64, SymlinkBase64, Dir], Field(discriminator="type")
]
r"""Content response"""


GetByOrgByRepoContentResponseTypedDict = TypeAliasType(
    "GetByOrgByRepoContentResponseTypedDict",
    Union[GetByOrgByRepoContentResponseBodyTypedDict, httpx.Response],
)


GetByOrgByRepoContentResponse = TypeAliasType(
    "GetByOrgByRepoContentResponse",
    Union[GetByOrgByRepoContentResponseBody, httpx.Response],
)
