# Orchestrator Service Schema
# Workflow engine configuration with queue, batch, extensions, and rollback

let workspace_schema = import "./common/workspace.ncl" in
let server_schema = import "./common/server.ncl" in
let database_schema = import "./common/database.ncl" in
let security_schema = import "./common/security.ncl" in
let monitoring_schema = import "./common/monitoring.ncl" in
let logging_schema = import "./common/logging.ncl" in
let storage_schema = import "./common/storage.ncl" in

{
  OrchestratorConfig = {
    # Workspace configuration
    workspace | workspace_schema.WorkspaceConfig,

    # HTTP server settings
    server | server_schema.ServerConfig,

    # Storage configuration
    storage | storage_schema.StorageConfig,

    # Queue Configuration - Task processing
    queue | {
      # Maximum concurrent tasks
      max_concurrent_tasks | Number,

      # Retry configuration
      retry_attempts | Number | default = 3,
      retry_delay | Number | default = 5000,

      # Task timeout in milliseconds
      task_timeout | Number | default = 3600000,

      # Queue persistence
      persist | Bool | default = true,

      # Dead letter queue for failed tasks
      dead_letter_queue | {
        enabled | Bool | default = true,
        max_size | Number | optional,
      } | optional,

      # Priority queue support
      priority_queue | Bool | default = false,

      # Queue metrics
      metrics | Bool | default = false,
    },

    # Batch Workflow Configuration
    batch | {
      # Parallel operation limit
      parallel_limit | Number | default = 5,

      # Batch operation timeout in milliseconds
      operation_timeout | Number | default = 1800000,

      # Checkpoint settings
      checkpointing | {
        enabled | Bool | default = true,
        interval | Number | optional,
        max_checkpoints | Number | optional,
      } | optional,

      # Rollback settings
      rollback | {
        enabled | Bool | default = true,
        strategy | String | optional,
        max_rollback_depth | Number | optional,
      } | optional,

      # Batch metrics
      metrics | Bool | default = false,
    },

    # Extensions Configuration
    extensions | {
      # Enable OCI extension loading
      auto_load | Bool | default = false,

      # OCI registry for extensions
      oci_registry_url | String | optional,
      oci_namespace | String | optional,

      # Extension discovery interval (seconds)
      discovery_interval | Number | optional,

      # Max concurrent extension operations
      max_concurrent | Number | optional,

      # Extension timeout in milliseconds
      timeout | Number | optional,

      # Extension sandboxing
      sandbox | Bool | default = true,
    } | optional,

    # Monitoring configuration
    monitoring | monitoring_schema.MonitoringConfig | optional,

    # Logging configuration
    logging | logging_schema.LoggingConfig | optional,

    # Security configuration
    security | security_schema.SecurityConfig | optional,

    # Performance tuning
    performance | {
      # Enable performance profiling
      profiling | Bool | default = false,

      # CPU affinity (pin threads to cores)
      cpu_affinity | Bool | default = false,

      # Memory limits
      memory_limits | {
        max_heap_mb | Number | optional,
        gc_threshold | Number | optional,
      } | optional,
    } | optional,
  },
}
