# generated by datamodel-codegen:
#   filename:  https://raw.githubusercontent.com/ga4gh/workflow-execution-service-schemas/develop/openapi/workflow_execution_service.openapi.yaml
#   timestamp: 2025-11-18T17:23:28+00:00

from __future__ import annotations

from enum import Enum
from typing import (
    Any,
    Optional,
    Union,
)

from pydantic import (
    AnyUrl,
    AwareDatetime,
    BaseModel,
    Field,
)


class Organization(BaseModel):
    name: str = Field(
        ..., description="Name of the organization responsible for the service", examples=["My organization"]
    )
    url: AnyUrl = Field(
        ..., description="URL of the website of the organization (RFC 3986 format)", examples=["https://example.com"]
    )


class ServiceType(BaseModel):
    group: str = Field(
        ...,
        description="Namespace in reverse domain name format. Use `org.ga4gh` for implementations compliant with official GA4GH specifications. For services with custom APIs not standardized by GA4GH, or implementations diverging from official GA4GH specifications, use a different namespace (e.g. your organization's reverse domain name).",
        examples=["org.ga4gh"],
    )
    artifact: str = Field(
        ...,
        description="Name of the API or GA4GH specification implemented. Official GA4GH types should be assigned as part of standards approval process. Custom artifacts are supported.",
        examples=["beacon"],
    )
    version: str = Field(
        ...,
        description="Version of the API or specification. GA4GH specifications use semantic versioning.",
        examples=["1.0.0"],
    )


class RunId(BaseModel):
    run_id: Optional[str] = Field(None, description="workflow run ID")


class State(Enum):
    UNKNOWN = "UNKNOWN"
    QUEUED = "QUEUED"
    INITIALIZING = "INITIALIZING"
    RUNNING = "RUNNING"
    PAUSED = "PAUSED"
    COMPLETE = "COMPLETE"
    EXECUTOR_ERROR = "EXECUTOR_ERROR"
    SYSTEM_ERROR = "SYSTEM_ERROR"
    CANCELED = "CANCELED"
    CANCELING = "CANCELING"
    PREEMPTED = "PREEMPTED"


class RunStatus(BaseModel):
    run_id: str
    state: Optional[State] = None


class RunSummary(RunStatus):
    start_time: Optional[str] = Field(
        None, description='When the run started executing, in ISO 8601 format "%Y-%m-%dT%H:%M:%SZ"'
    )
    end_time: Optional[str] = Field(
        None,
        description='When the run stopped executing (completed, failed, or cancelled), in ISO 8601 format "%Y-%m-%dT%H:%M:%SZ"',
    )
    tags: dict[str, str] = Field(..., description="Arbitrary key/value tags added by the client during run creation")


class RunRequest(BaseModel):
    workflow_params: Optional[dict[str, Any]] = Field(
        None,
        description="REQUIRED\nThe workflow run parameterizations (JSON encoded), including input and output file locations",
    )
    workflow_type: str = Field(
        ...,
        description='REQUIRED\nThe workflow descriptor type, must be "CWL" or "WDL" currently (or another alternative supported by this WES instance)',
    )
    workflow_type_version: str = Field(
        ..., description="REQUIRED\nThe workflow descriptor type version, must be one supported by this WES instance"
    )
    tags: Optional[dict[str, str]] = None
    workflow_engine_parameters: Optional[dict[str, str]] = None
    workflow_engine: Optional[str] = Field(
        None,
        description="The workflow engine, must be one supported by this WES instance. Required if workflow_engine_version is provided.",
    )
    workflow_engine_version: Optional[str] = Field(
        None,
        description="The workflow engine version, must be one supported by this WES instance. If workflow_engine is provided, but workflow_engine_version is not, servers can make no assumptions with regard to the engine version the WES instance uses to process the request if  that WES instance supports multiple versions of the requested engine.",
    )
    workflow_url: str = Field(
        ...,
        description="REQUIRED\nThe workflow CWL or WDL document. When `workflow_attachments` is used to attach files, the `workflow_url` may be a relative path to one of the attachments.",
    )


class Log(BaseModel):
    name: Optional[str] = Field(None, description="The task or workflow name")
    cmd: Optional[list[str]] = Field(None, description="The command line that was executed")
    start_time: Optional[str] = Field(
        None, description='When the command started executing, in ISO 8601 format "%Y-%m-%dT%H:%M:%SZ"'
    )
    end_time: Optional[str] = Field(
        None,
        description='When the command stopped executing (completed, failed, or cancelled), in ISO 8601 format "%Y-%m-%dT%H:%M:%SZ"',
    )
    stdout: Optional[str] = Field(
        None,
        description="A URL to retrieve standard output logs of the workflow run or task.  This URL may change between status requests, or may not be available until the task or workflow has finished execution.  Should be available using the same credentials used to access the WES endpoint.",
    )
    stderr: Optional[str] = Field(
        None,
        description="A URL to retrieve standard error logs of the workflow run or task.  This URL may change between status requests, or may not be available until the task or workflow has finished execution.  Should be available using the same credentials used to access the WES endpoint.",
    )
    exit_code: Optional[int] = Field(None, description="Exit code of the program")
    system_logs: Optional[list[str]] = Field(
        None,
        description="System logs are any logs the system decides are relevant,\nwhich are not tied directly to a workflow.\nContent is implementation specific: format, size, etc.\n\nSystem logs may be collected here to provide convenient access.\n\nFor example, the system may include an error message that caused\na SYSTEM_ERROR state (e.g. disk is full), etc.",
    )


class DefaultWorkflowEngineParameter(BaseModel):
    name: Optional[str] = Field(None, description="The name of the parameter")
    type: Optional[str] = Field(None, description="Describes the type of the parameter, e.g. float.")
    default_value: Optional[str] = Field(
        None, description='The stringified version of the default parameter. e.g. "2.45".'
    )


class WorkflowTypeVersion(BaseModel):
    workflow_type_version: Optional[list[str]] = Field(
        None, description="an array of one or more acceptable types for the `workflow_type`"
    )


class TaskLog(Log):
    id: str = Field(..., description="A unique identifier which may be used to reference the task")
    system_logs: Optional[list[str]] = Field(
        None,
        description="System logs are any logs the system decides are relevant,\nwhich are not tied directly to a task.\nContent is implementation specific: format, size, etc.\n\nSystem logs may be collected here to provide convenient access.\n\nFor example, the system may include the name of the host\nwhere the task is executing, an error message that caused\na SYSTEM_ERROR state (e.g. disk is full), etc.",
    )
    tes_uri: Optional[str] = Field(
        None,
        description="An optional URL pointing to an extended task definition defined by a [TES api](https://github.com/ga4gh/task-execution-schemas)",
    )
    name: str = Field(..., description="The task or workflow name")


class WorkflowEngineVersion(BaseModel):
    workflow_engine_version: Optional[list[str]] = Field(
        None, description="An array of one or more acceptable engines versions for the `workflow_engine`"
    )


class RunListResponse(BaseModel):
    runs: Optional[list[Union[RunStatus, RunSummary]]] = Field(
        None,
        description="A list of workflow runs that the service has executed or is executing. The list is filtered to only include runs that the caller has permission to see.",
    )
    next_page_token: Optional[str] = Field(
        None,
        description="A token which may be supplied as `page_token` in workflow run list request to get the next page of results.  An empty string indicates there are no more items to return.",
    )


class ErrorResponse(BaseModel):
    msg: Optional[str] = Field(None, description="A detailed error message.")
    status_code: Optional[int] = Field(
        None, description="The integer representing the HTTP status code (e.g. 200, 404)."
    )


class Service(BaseModel):
    id: str = Field(
        ...,
        description="Unique ID of this service. Reverse domain name notation is recommended, though not required. The identifier should attempt to be globally unique so it can be used in downstream aggregator services e.g. Service Registry.",
        examples=["org.ga4gh.myservice"],
    )
    name: str = Field(..., description="Name of this service. Should be human readable.", examples=["My project"])
    type: ServiceType
    description: Optional[str] = Field(
        None,
        description="Description of the service. Should be human readable and provide information about the service.",
        examples=["This service provides..."],
    )
    organization: Organization = Field(..., description="Organization providing the service")
    contactUrl: Optional[AnyUrl] = Field(
        None,
        description="URL of the contact for the provider of this service, e.g. a link to a contact form (RFC 3986 format), or an email (RFC 2368 format).",
        examples=["mailto:support@example.com"],
    )
    documentationUrl: Optional[AnyUrl] = Field(
        None,
        description="URL of the documentation of this service (RFC 3986 format). This should help someone learn how to use your service, including any specifics required to access data, e.g. authentication.",
        examples=["https://docs.myservice.example.com"],
    )
    createdAt: Optional[AwareDatetime] = Field(
        None,
        description="Timestamp describing when the service was first deployed and available (RFC 3339 format)",
        examples=["2019-06-04T12:58:19Z"],
    )
    updatedAt: Optional[AwareDatetime] = Field(
        None,
        description="Timestamp describing when the service was last updated (RFC 3339 format)",
        examples=["2019-06-04T12:58:19Z"],
    )
    environment: Optional[str] = Field(
        None,
        description="Environment the service is running in. Use this to distinguish between production, development and testing/staging deployments. Suggested values are prod, test, dev, staging. However this is advised and not enforced.",
        examples=["test"],
    )
    version: str = Field(
        ...,
        description="Version of the service being described. Semantic versioning is recommended, but other identifiers, such as dates or commit hashes, are also allowed. The version should be changed whenever the service is updated.",
        examples=["1.0.0"],
    )


class RunLog(BaseModel):
    run_id: Optional[str] = Field(None, description="workflow run ID")
    request: Optional[RunRequest] = None
    state: Optional[State] = None
    run_log: Optional[Log] = None
    task_logs_url: Optional[str] = Field(
        None,
        description="A reference to the complete url which may be used to obtain a paginated list of task logs for this workflow",
    )
    task_logs: Optional[list[Union[Log, TaskLog]]] = Field(
        None,
        description="The logs, and other key info like timing and exit code, for each step in the workflow run. This field is deprecated and the `task_logs_url` should be used to retrieve a paginated list of steps from the workflow run. This field will be removed in the next major version of the  specification (2.0.0)",
    )
    outputs: Optional[dict[str, Any]] = Field(None, description="The outputs from the workflow run.")


class TaskListResponse(BaseModel):
    task_logs: Optional[list[TaskLog]] = Field(
        None, description="The logs, and other key info like timing and exit code, for each step in the workflow run."
    )
    next_page_token: Optional[str] = Field(
        None,
        description="A token which may be supplied as `page_token` in workflow run task list request to get the next page of results.  An empty string indicates there are no more items to return.",
    )


class ServiceInfo(Service):
    workflow_type_versions: dict[str, WorkflowTypeVersion]
    supported_wes_versions: list[str] = Field(
        ..., description="The version(s) of the WES schema supported by this service"
    )
    supported_filesystem_protocols: list[str] = Field(
        ...,
        description="The filesystem protocols supported by this service, currently these may include common protocols using the terms 'http', 'https', 'sftp', 's3', 'gs', 'file', or 'synapse', but others  are possible and the terms beyond these core protocols are currently not fixed.   This section reports those protocols (either common or not) supported by this WES service.",
    )
    workflow_engine_versions: dict[str, WorkflowEngineVersion]
    default_workflow_engine_parameters: list[DefaultWorkflowEngineParameter] = Field(
        ...,
        description="Each workflow engine can present additional parameters that can be sent to the workflow engine. This message will list the default values, and their types for each workflow engine.",
    )
    system_state_counts: dict[str, int] = Field(
        ...,
        description="The system statistics, key is the statistic, value is the count of runs in that state. See the State enum for the possible keys.",
    )
    auth_instructions_url: str = Field(
        ...,
        description="A web page URL with human-readable instructions on how to get an authorization token for use with a specific WES endpoint.",
    )
    tags: dict[str, str]
