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

from __future__ import annotations
from mesa_sdk.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedStr
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, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


Period = Literal[
    "24h",
    "1w",
    "1m",
    "all",
]


class GetByOrgByRepoAnalyticsRequestTypedDict(TypedDict):
    org: str
    repo: str
    period: NotRequired[Period]


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

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

    period: Annotated[
        Optional[Period],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "all"

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


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


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


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


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


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


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


class GetByOrgByRepoAnalyticsBadRequestError(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 GetByOrgByRepoAnalyticsSummaryTypedDict(TypedDict):
    total_lines: float
    ai_lines: float
    human_lines: float
    providers: Dict[str, float]
    models: Dict[str, float]
    updated: str


class GetByOrgByRepoAnalyticsSummary(BaseModel):
    total_lines: Annotated[float, pydantic.Field(alias="totalLines")]

    ai_lines: Annotated[float, pydantic.Field(alias="aiLines")]

    human_lines: Annotated[float, pydantic.Field(alias="humanLines")]

    providers: Dict[str, float]

    models: Dict[str, float]

    updated: str


class GetByOrgByRepoAnalyticsContributorsTypedDict(TypedDict):
    total_lines: float
    ai_lines: float
    providers: Dict[str, float]
    models: Dict[str, float]
    commit_count: float


class GetByOrgByRepoAnalyticsContributors(BaseModel):
    total_lines: Annotated[float, pydantic.Field(alias="totalLines")]

    ai_lines: Annotated[float, pydantic.Field(alias="aiLines")]

    providers: Dict[str, float]

    models: Dict[str, float]

    commit_count: Annotated[float, pydantic.Field(alias="commitCount")]


class GetByOrgByRepoAnalyticsHistoryTypedDict(TypedDict):
    date_: str
    sha: str
    author: str
    added: float
    removed: float
    ai_lines: float
    message: NotRequired[str]
    providers: NotRequired[Dict[str, float]]
    models: NotRequired[Dict[str, float]]


class GetByOrgByRepoAnalyticsHistory(BaseModel):
    date_: Annotated[str, pydantic.Field(alias="date")]

    sha: str

    author: str

    added: float

    removed: float

    ai_lines: Annotated[float, pydantic.Field(alias="aiLines")]

    message: Optional[str] = None

    providers: Optional[Dict[str, float]] = None

    models: Optional[Dict[str, float]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["message", "providers", "models"])
        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 GetByOrgByRepoAnalyticsMetaTypedDict(TypedDict):
    last_attempt: str
    last_success: Nullable[str]
    last_error: Nullable[str]


class GetByOrgByRepoAnalyticsMeta(BaseModel):
    last_attempt: Annotated[str, pydantic.Field(alias="lastAttempt")]

    last_success: Annotated[Nullable[str], pydantic.Field(alias="lastSuccess")]

    last_error: Annotated[Nullable[str], pydantic.Field(alias="lastError")]

    @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 GetByOrgByRepoAnalyticsAnalyticsTypedDict(TypedDict):
    summary: GetByOrgByRepoAnalyticsSummaryTypedDict
    contributors: Dict[str, GetByOrgByRepoAnalyticsContributorsTypedDict]
    history: List[GetByOrgByRepoAnalyticsHistoryTypedDict]
    version: float
    meta: NotRequired[GetByOrgByRepoAnalyticsMetaTypedDict]


class GetByOrgByRepoAnalyticsAnalytics(BaseModel):
    summary: GetByOrgByRepoAnalyticsSummary

    contributors: Dict[str, GetByOrgByRepoAnalyticsContributors]

    history: List[GetByOrgByRepoAnalyticsHistory]

    version: Annotated[
        Annotated[float, AfterValidator(validate_const(2))],
        pydantic.Field(alias="version"),
    ] = 2

    meta: Annotated[
        Optional[GetByOrgByRepoAnalyticsMeta], pydantic.Field(alias="_meta")
    ] = None

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


GetByOrgByRepoAnalyticsStatus = Union[
    Literal[
        "current",
        "stale",
        "none",
    ],
    UnrecognizedStr,
]


class GetByOrgByRepoAnalyticsResponseTypedDict(TypedDict):
    r"""Analytics data"""

    analytics: Nullable[GetByOrgByRepoAnalyticsAnalyticsTypedDict]
    status: GetByOrgByRepoAnalyticsStatus


class GetByOrgByRepoAnalyticsResponse(BaseModel):
    r"""Analytics data"""

    analytics: Nullable[GetByOrgByRepoAnalyticsAnalytics]

    status: GetByOrgByRepoAnalyticsStatus

    @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
