# flake8: noqa
# generated by datamodel-codegen:
#   filename:  openapi.json
#   source_sha256: 38958367ca13c1d4f0d7748d743e43e6b7e87b350e9286ff1aa144dcedad0fcc

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any
from uuid import UUID

from pydantic import BaseModel, Extra, Field


class AccessTokenResponse(BaseModel):
    access_token: str = Field(..., title="Access Token")
    token_type: str | None = Field(default="bearer", title="Token Type")
    expires_in: int = Field(..., title="Expires In")
    expiration: int | None = Field(default=None, title="Expiration")


class AccessUrlResponse(BaseModel):
    url: str = Field(..., title="Url")


class BatchStatusRequest(BaseModel):
    job_ids: list[UUID] = Field(..., title="Job Ids")


class BodyOidcTokenApiV1OidcTokenPost(BaseModel):
    grant_type: str = Field(..., title="Grant Type")
    code: str = Field(..., title="Code")
    client_id: str = Field(..., title="Client Id")
    client_secret: str = Field(..., title="Client Secret")
    redirect_uri: str | None = Field(default="", title="Redirect Uri")


class CheckProgressRequest(BaseModel):
    id: UUID = Field(..., title="Id")


class Status(Enum):
    running = "running"
    done = "done"


class CheckProgressResponse(BaseModel):
    id: UUID = Field(..., title="Id")
    status: Status = Field(..., title="Status")
    report: Any = Field(default=None, title="Report")


class CheckStartRequest(BaseModel):
    s3_bucket: str | None = Field(default=None, title="S3 Bucket")
    nfs_path: str | None = Field(default=None, title="Nfs Path")
    package_environment: str | None = Field(default=None, title="Package Environment")
    recipe_name: str | None = Field(default=None, title="Recipe Name")
    recipe_args: dict[str, Any] | None = Field(default=None, title="Recipe Args")


class CheckStartResponse(BaseModel):
    id: UUID = Field(..., title="Id")


class Copying(BaseModel):
    src: str = Field(..., title="Src")
    dest: str = Field(..., title="Dest")
    make_dirs: bool = Field(..., title="Make Dirs")
    overwrite: bool = Field(..., title="Overwrite")


class Dataset(BaseModel):
    name: str = Field(
        ..., description="a unique name for the dataset", title="Dataset Name"
    )
    created: datetime | None = Field(
        default=None,
        description="the date and time that the dataset was created",
        title="Created Time",
    )
    meta: str | None = Field(
        default="{}",
        description="An arbitrary JSON string containing metadata for your dataset",
        title="Dataset Metadata",
    )
    session: bool | None = Field(
        default=False,
        description="True when the dataset contains examples for a user session",
        title="Session Dataset",
    )


class DatasetCreating(BaseModel):
    author: str | None = Field(
        default="",
        description="the user that authored created dataset",
        title="Dataset Author",
    )
    description: str | None = Field(
        default="",
        description="human readable description of what kind of examples the dataset contains",
        title="Dataset Description",
    )
    created: datetime | None = Field(
        default=None,
        description="the date and time that the dataset was created",
        title="Created Time",
    )
    name: str = Field(
        ..., description="a unique name for the dataset", title="Dataset Name"
    )


class DatasetExample(BaseModel):
    class Config:
        extra = Extra.allow

    id: int = Field(..., description="The database id", ge=1, title="Id")
    input_hash: int = Field(
        ..., description="The hash value of the input", title="Input Hash"
    )
    task_hash: int = Field(
        ..., description="The hash value of the task", title="Task Hash"
    )
    content: dict[str, Any] = Field(
        ..., description="The dict content of the example", title="Content"
    )


class Deleting(BaseModel):
    path: str = Field(..., title="Path")
    missing_ok: bool | None = Field(default=True, title="Missing Ok")
    recurse: bool | None = Field(default=False, title="Recurse")


class Downloading(BaseModel):
    target: str = Field(..., title="Target")


class EnvCreateStatus(BaseModel):
    package_name: str = Field(..., title="Package Name")
    package_version: str = Field(..., title="Package Version")
    python_version: str = Field(..., title="Python Version")
    path: str = Field(..., title="Path")
    job_id: str = Field(..., title="Job Id")
    eval_id: str = Field(..., title="Eval Id")
    is_ready: bool = Field(..., title="Is Ready")
    alloc_id: str | None = Field(default=None, title="Alloc Id")
    status: str | None = Field(default=None, title="Status")
    logs: str | None = Field(default=None, title="Logs")


class FileCopyPlan(BaseModel):
    src: str = Field(..., title="Src")
    dest: str = Field(..., title="Dest")


class FileStats(BaseModel):
    size: int = Field(..., title="Size")
    modification_time: datetime = Field(..., title="Modification Time")


class Status1(Enum):
    SUCCESS = "SUCCESS"
    FAILED = "FAILED"
    INVALID = "INVALID"


class Action(Enum):
    start = "start"
    stop = "stop"
    delete = "delete"


class JobError(BaseModel):
    timestamp: datetime | None = Field(default=None, title="Timestamp")
    message: str = Field(..., title="Message")
    traceback: str | None = Field(default=None, title="Traceback")


class JobErrorsResponse(BaseModel):
    job_id: UUID = Field(..., title="Job Id")
    state: str = Field(..., title="State")
    errors: list[JobError] = Field(..., title="Errors")
    tail: str | None = Field(default=None, title="Tail")


class JobLogRequest(BaseModel):
    id: UUID = Field(..., title="Id")
    tail_lines: int | None = Field(default=200, title="Tail Lines")
    since_seconds: int | None = Field(default=None, title="Since Seconds")


class JobLogResponse(BaseModel):
    text: str | None = Field(..., title="Text")
    source: str | None = Field(default=None, title="Source")


class JobState(Enum):
    not_found = "not_found"
    pending = "pending"
    running = "running"
    ready = "ready"
    succeeded = "succeeded"
    failed = "failed"
    stopped = "stopped"
    unknown = "unknown"


class JobType(Enum):
    task = "task"
    action = "action"
    agent = "agent"


class K8sActionResponse(BaseModel):
    action: str = Field(..., title="Action")
    job_id: UUID = Field(..., title="Job Id")
    resource_version: str | None = Field(default=None, title="Resource Version")


class K8sErrorResponse(BaseModel):
    status_code: int = Field(..., title="Status Code")
    body: str = Field(..., title="Body")
    resource: str = Field(..., title="Resource")
    method: str = Field(..., title="Method")


class K8sPodSummary(BaseModel):
    name: str = Field(..., title="Name")
    phase: str | None = Field(default=None, title="Phase")
    uid: str | None = Field(default=None, title="Uid")


class K8sResources(BaseModel):
    cpu_cores: float | None = Field(default=None, title="Cpu Cores")
    memory_mb: int | None = Field(default=None, title="Memory Mb")
    memory_max_mb: int | None = Field(default=None, title="Memory Max Mb")


class Listing(BaseModel):
    path: str = Field(..., title="Path")
    recurse: bool = Field(..., title="Recurse")
    include_stats: bool | None = Field(default=False, title="Include Stats")


class LogSource(Enum):
    auto = "auto"
    k8s = "k8s"
    loki = "loki"


class NodeConditionSummary(BaseModel):
    type: str = Field(..., title="Type")
    status: str = Field(..., title="Status")
    reason: str | None = Field(default=None, title="Reason")
    message: str | None = Field(default=None, title="Message")


class NodePodSummary(BaseModel):
    name: str = Field(..., title="Name")
    phase: str | None = Field(default=None, title="Phase")
    job_id: str | None = Field(default=None, title="Job Id")
    job_type: str | None = Field(default=None, title="Job Type")


class NodeResources(BaseModel):
    cpu: str = Field(..., title="Cpu")
    memory: str = Field(..., title="Memory")
    gpu: int | None = Field(default=None, title="Gpu")


class NodeSummary(BaseModel):
    name: str = Field(..., title="Name")
    status: str = Field(..., title="Status")
    roles: list[str] = Field(..., title="Roles")
    capacity: NodeResources
    allocatable: NodeResources
    labels: dict[str, str] = Field(..., title="Labels")
    pod_count: int = Field(..., title="Pod Count")


class PageDatasetExample(BaseModel):
    items: list[DatasetExample] = Field(..., title="Items")
    total: int = Field(..., ge=0, title="Total")
    page: int = Field(..., ge=1, title="Page")
    size: int = Field(..., ge=1, title="Size")
    pages: int = Field(..., ge=0, title="Pages")


class PageStr(BaseModel):
    items: list[str] = Field(..., title="Items")
    total: int = Field(..., ge=0, title="Total")
    page: int = Field(..., ge=1, title="Page")
    size: int = Field(..., ge=1, title="Size")
    pages: int = Field(..., ge=0, title="Pages")


class PathList(BaseModel):
    paths: list[str] = Field(..., title="Paths")
    stats: list[FileStats] | None = Field(..., title="Stats")
    exists: bool = Field(..., title="Exists")
    is_file: bool = Field(..., title="Is File")


class ProdigyLoginResponse(BaseModel):
    session_id: UUID = Field(..., title="Session Id")
    user_id: UUID = Field(..., title="User Id")
    task_id: UUID = Field(..., title="Task Id")
    login_token: str = Field(..., title="Login Token")


class ReadExamplesRequest(BaseModel):
    datasets: list[str] = Field(..., title="Datasets")


class RecipePlan(BaseModel):
    recipe_name: str = Field(..., title="Recipe Name")
    command: list[str] | None = Field(default=None, title="Command")
    args: dict[str, Any] | None = Field(default=None, title="Args")
    positional_fields: list[str] | None = Field(default=None, title="Positional Fields")
    cli_names: dict[str, str] | None = Field(default=None, title="Cli Names")
    package_name: str | None = Field(default="", title="Package Name")
    environment: str | None = Field(default=None, title="Environment")
    objects: dict[str, dict[str, Any]] | None = Field(default={}, title="Objects")


class RecipesMeta(BaseModel):
    recipes: list[bool | int | float | str | list[Any] | dict[str, Any] | None] = Field(
        ..., title="Recipes"
    )


class Requirement(BaseModel):
    name: str = Field(..., title="Name")
    specifier: str | None = Field(default=None, title="Specifier")
    url: str | None = Field(default=None, title="Url")
    extras: list[str] | None = Field(default=None, title="Extras")
    marker: str | None = Field(default=None, title="Marker")


class RsyncPlan(BaseModel):
    copy_: list[FileCopyPlan] = Field(..., title="Copy")
    delete: list[str] = Field(..., title="Delete")
    file_exists: list[str] = Field(..., title="File Exists")
    directory_missing: list[str] = Field(..., title="Directory Missing")


class Secret(BaseModel):
    key: str = Field(..., title="Key")
    value: dict[str, bool | int | float | str | list[Any] | dict[str, Any] | None] = (
        Field(..., title="Value")
    )


class SecretReading(BaseModel):
    key: str = Field(..., title="Key")


class SecretResponse(BaseModel):
    name: str = Field(..., title="Name")
    data: dict[str, str] = Field(..., title="Data")


class SignedUrl(BaseModel):
    url: str = Field(..., title="Url")
    method: str = Field(..., title="Method")
    expiry: datetime = Field(..., title="Expiry")


class SpecValidationFailure(BaseModel):
    message: str = Field(..., title="Message")
    errors: list[dict[str, Any]] = Field(..., title="Errors")


class Statting(BaseModel):
    path: str = Field(..., title="Path")


class StatusModel(Enum):
    Ready = "Ready"
    Error = "Error"


class TasksBaseUrl(BaseModel):
    url: str = Field(..., title="Url")


class TokenExchangeRequest(BaseModel):
    token: str = Field(..., title="Token")
    scope: str | None = Field(default="advanced", title="Scope")


class ValidationError(BaseModel):
    loc: list[str | int] = Field(..., title="Location")
    msg: str = Field(..., title="Message")
    type: str = Field(..., title="Error Type")
    input: Any | None = Field(default=None, title="Input")
    ctx: dict[str, Any] | None = Field(default=None, title="Context")


class VersionInfo(BaseModel):
    service: str = Field(..., title="Service")
    package_version: str = Field(..., title="Package Version")
    repo_sha: str = Field(..., title="Repo Sha")
    service_sha: str = Field(..., title="Service Sha")
    container_sha: str = Field(..., title="Container Sha")
    build_date: str = Field(..., title="Build Date")


class WorkerJobResources(BaseModel):
    cores: float | None = Field(default=None, title="Cores")
    memory_mb: int | None = Field(default=None, title="Memory Mb")
    memory_max_mb: int | None = Field(default=None, title="Memory Max Mb")


class WorkerType(BaseModel):
    name: str = Field(..., title="Name")
    node_class: str | None = Field(default=None, title="Node Class")
    per_job: WorkerJobResources | None = None
    description: str | None = Field(default=None, title="Description")
    image_id: str | None = Field(default="cpu", title="Image Id")


class BodyApiV1UploadFileApiV1FilesUploadPost(BaseModel):
    file: bytes = Field(..., description="File to Upload with valid name", title="File")


class CopyPlan(BaseModel):
    copy_: list[FileCopyPlan] = Field(..., title="Copy")
    file_exists: list[str] = Field(..., title="File Exists")
    directory_missing: list[str] = Field(..., title="Directory Missing")


class EnvCreate(BaseModel):
    package_path: str = Field(..., title="Package Path")
    is_dist_package: bool = Field(..., title="Is Dist Package")
    requirements_txt: str | None = Field(default=None, title="Requirements Txt")
    requirements: list[Requirement] | None = Field(default=None, title="Requirements")
    deps: list[str] | None = Field(default=[], title="Deps")


class EnvCreateResponse(BaseModel):
    status: EnvCreateStatus | None = None
    validation_error: SpecValidationFailure | None = None
    cluster_error: K8sErrorResponse | None = None


class HTTPValidationError(BaseModel):
    detail: list[ValidationError] | None = Field(default=None, title="Detail")


class HealthCheck(BaseModel):
    status: StatusModel
    cluster: StatusModel
    cluster_error: K8sErrorResponse | None


class JobActionResponse(BaseModel):
    job_id: UUID = Field(..., title="Job Id")
    attempt_id: UUID | None = Field(..., title="Attempt Id")
    status: Status1 = Field(..., title="Status")
    action: Action = Field(..., title="Action")
    job_type: JobType
    validation_error: SpecValidationFailure | None = None
    cluster_error: K8sErrorResponse | None = None
    cluster_change: K8sActionResponse | None = None


class JobID(BaseModel):
    id: UUID = Field(..., title="Id")
    job_type: JobType


class JobSpec(BaseModel):
    job_id: UUID = Field(..., title="Job Id")
    job_type: JobType
    name: str = Field(..., title="Name")
    plan: RecipePlan
    resources: K8sResources | None = None
    node_selector: dict[str, str] | None = Field(default=None, title="Node Selector")
    worker_type: str | None = Field(default=None, title="Worker Type")
    image_id: str | None = Field(default=None, title="Image Id")


class JobStatus(BaseModel):
    job_id: UUID = Field(..., title="Job Id")
    job_type: str | None = Field(default=None, title="Job Type")
    state: JobState
    is_ready: bool = Field(..., title="Is Ready")
    pods: list[K8sPodSummary] = Field(..., title="Pods")
    message: str | None = Field(default=None, title="Message")


class NodeDetail(BaseModel):
    name: str = Field(..., title="Name")
    status: str = Field(..., title="Status")
    roles: list[str] = Field(..., title="Roles")
    capacity: NodeResources
    allocatable: NodeResources
    labels: dict[str, str] = Field(..., title="Labels")
    pod_count: int = Field(..., title="Pod Count")
    pods: list[NodePodSummary] = Field(..., title="Pods")
    conditions: list[NodeConditionSummary] = Field(..., title="Conditions")
    addresses: list[dict[str, str]] = Field(..., title="Addresses")


class BatchStatusResponse(BaseModel):
    statuses: dict[str, JobStatus] = Field(..., title="Statuses")
