# Copyright (c) 2025-2026 Dmitrii Gagarin aka madgagarin
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""
Centralized constants for the RXON protocol.
Shared between Orchestrator and Worker SDK.
"""

__all__ = [
    "AUTH_HEADER_CLIENT",
    "AUTH_HEADER_WORKER",
    "ERROR_CODE_TRANSIENT",
    "ERROR_CODE_PERMANENT",
    "ERROR_CODE_INVALID_INPUT",
    "ERROR_CODE_INTEGRITY_MISMATCH",
    "ERROR_CODE_TIMEOUT",
    "ERROR_CODE_LATE_RESULT",
    "ERROR_CODE_RESOURCE_EXHAUSTED",
    "ERROR_CODE_LIMIT_EXCEEDED",
    "ERROR_CODE_DEPENDENCY_MISSING",
    "ERROR_CODE_CONTRACT_VIOLATION",
    "ERROR_CODE_DEPENDENCY",
    "ERROR_CODE_SECURITY",
    "ERROR_CODE_INTERNAL",
    "TASK_STATUS_SUCCESS",
    "TASK_STATUS_FAILURE",
    "TASK_STATUS_CANCELLED",
    "COMMAND_CANCEL_TASK",
    "EVENT_TYPE_PROGRESS",
    "STS_TOKEN_ENDPOINT",
    "WS_ENDPOINT",
    "ENDPOINT_WORKER_REGISTER",
    "ENDPOINT_TASK_NEXT",
    "ENDPOINT_TASK_RESULT",
    "ENDPOINT_WORKER_HEARTBEAT",
    "ENDPOINT_WORKER_EVENTS",
    "JOB_STATUS_PENDING",
    "JOB_STATUS_WAITING_FOR_WORKER",
    "JOB_STATUS_RUNNING",
    "JOB_STATUS_FINISHED",
    "JOB_STATUS_FAILED",
    "JOB_STATUS_ERROR",
    "JOB_STATUS_QUARANTINED",
    "JOB_STATUS_CANCELLED",
    "JOB_STATUS_WAITING_FOR_HUMAN",
    "JOB_STATUS_WAITING_FOR_PARALLEL",
    "WORKER_API_PREFIX",
    "PROTOCOL_VERSION",
    "PROTOCOL_VERSION_HEADER",
    "IGNORED_REASON_LATE",
    "IGNORED_REASON_CANCELLED",
    "IGNORED_REASON_NOT_FOUND",
    "IGNORED_REASON_MISMATCH",
    "IGNORED_REASON_STALE",
    "HB_RESP_REQUIRE_FULL_SYNC",
    "HB_RESP_CANCEL_TASKS",
]

PROTOCOL_VERSION = "1.0b6"
PROTOCOL_VERSION_HEADER = "X-RXON-Version"

AUTH_HEADER_CLIENT = "X-Client-Token"
AUTH_HEADER_WORKER = "X-Worker-Token"

ERROR_CODE_TRANSIENT = "TRANSIENT_ERROR"
ERROR_CODE_PERMANENT = "PERMANENT_ERROR"
ERROR_CODE_INVALID_INPUT = "INVALID_INPUT_ERROR"
ERROR_CODE_INTEGRITY_MISMATCH = "INTEGRITY_MISMATCH_ERROR"
ERROR_CODE_TIMEOUT = "TIMEOUT_ERROR"
ERROR_CODE_LATE_RESULT = "LATE_RESULT"
ERROR_CODE_RESOURCE_EXHAUSTED = "RESOURCE_EXHAUSTED_ERROR"
ERROR_CODE_LIMIT_EXCEEDED = "LIMIT_EXCEEDED_ERROR"
ERROR_CODE_CONTRACT_VIOLATION = "CONTRACT_VIOLATION_ERROR"
ERROR_CODE_DEPENDENCY_MISSING = "DEPENDENCY_MISSING_ERROR"

IGNORED_REASON_LATE = "deadline_exceeded"
IGNORED_REASON_CANCELLED = "job_cancelled"
IGNORED_REASON_NOT_FOUND = "job_not_found"
IGNORED_REASON_MISMATCH = "worker_mismatch"
IGNORED_REASON_STALE = "stale_task"

HB_RESP_REQUIRE_FULL_SYNC = "require_full_sync"
HB_RESP_CANCEL_TASKS = "cancel_task_ids"

ERROR_CODE_DEPENDENCY = "DEPENDENCY_ERROR"
ERROR_CODE_SECURITY = "SECURITY_ERROR"
ERROR_CODE_INTERNAL = "INTERNAL_ERROR"

TASK_STATUS_SUCCESS = "success"
TASK_STATUS_FAILURE = "failure"
TASK_STATUS_CANCELLED = "cancelled"

COMMAND_CANCEL_TASK = "cancel_task"
EVENT_TYPE_PROGRESS = "progress"

WORKER_API_PREFIX = "/_worker"

STS_TOKEN_ENDPOINT = f"{WORKER_API_PREFIX}/auth/token"
WS_ENDPOINT = f"{WORKER_API_PREFIX}/ws"

ENDPOINT_WORKER_REGISTER = f"{WORKER_API_PREFIX}/workers/register"
ENDPOINT_TASK_NEXT = f"{WORKER_API_PREFIX}/workers/{{worker_id}}/tasks/next"
ENDPOINT_TASK_RESULT = f"{WORKER_API_PREFIX}/tasks/result"
ENDPOINT_WORKER_HEARTBEAT = f"{WORKER_API_PREFIX}/workers/{{worker_id}}"
ENDPOINT_WORKER_EVENTS = f"{WORKER_API_PREFIX}/events"

JOB_STATUS_PENDING = "pending"
JOB_STATUS_WAITING_FOR_WORKER = "waiting_for_worker"
JOB_STATUS_RUNNING = "running"
JOB_STATUS_FINISHED = "finished"
JOB_STATUS_FAILED = "failed"
JOB_STATUS_ERROR = "error"
JOB_STATUS_QUARANTINED = "quarantined"
JOB_STATUS_CANCELLED = "cancelled"
JOB_STATUS_WAITING_FOR_HUMAN = "waiting_for_human"
JOB_STATUS_WAITING_FOR_PARALLEL = "waiting_for_parallel_tasks"
