"""Pydantic models for GA4GH WES (Workflow Execution Service) v1.1."""

from __future__ import annotations

from enum import Enum
from typing import Any

from ai4gh.core.types import GA4GHBase


class State(str, Enum):
    """WES run state."""

    UNKNOWN = "UNKNOWN"
    QUEUED = "QUEUED"
    INITIALIZING = "INITIALIZING"
    RUNNING = "RUNNING"
    PAUSED = "PAUSED"
    COMPLETE = "COMPLETE"
    EXECUTOR_ERROR = "EXECUTOR_ERROR"
    SYSTEM_ERROR = "SYSTEM_ERROR"
    CANCELED = "CANCELED"
    CANCELING = "CANCELING"


class RunLog(GA4GHBase):
    """Log entry for a WES run."""

    name: str | None = None
    cmd: list[str] | None = None
    start_time: str | None = None
    end_time: str | None = None
    stdout: str | None = None
    stderr: str | None = None
    exit_code: int | None = None


class RunRequest(GA4GHBase):
    """WES run request."""

    workflow_params: dict[str, Any] | None = None
    workflow_type: str | None = None
    workflow_type_version: str | None = None
    workflow_engine_parameters: dict[str, str] | None = None
    workflow_url: str | None = None
    tags: dict[str, str] | None = None


class RunStatus(GA4GHBase):
    """Minimal run status (for list responses)."""

    run_id: str
    state: State


class RunListResponse(GA4GHBase):
    """WES run list response."""

    runs: list[RunStatus] | None = None
    next_page_token: str | None = None


class RunDescription(GA4GHBase):
    """Full run description (FULL view)."""

    run_id: str
    request: RunRequest | None = None
    state: State | None = None
    run_log: RunLog | None = None
    task_logs: list[RunLog] | None = None
    outputs: dict[str, Any] | None = None


class RunId(GA4GHBase):
    """Response when a run is submitted."""

    run_id: str


class ServiceInfo(GA4GHBase):
    """WES-specific service info extensions."""

    supported_wes_versions: list[str] | None = None
    supported_filesystem_protocols: list[str] | None = None
    workflow_type_versions: dict[str, Any] | None = None
    workflow_engine_versions: dict[str, Any] | None = None
    default_workflow_engine_parameters: list[dict[str, Any]] | None = None
    auth_instructions_url: str | None = None
    tags: dict[str, str] | None = None
