# Orchestrator Configuration - Nickel Format
# Auto-generated by provisioning TypeDialog
# Edit via: nu provisioning/.typedialog/provisioning/platform/scripts/configure.nu orchestrator {mode}
# Or manually edit and validate with: nickel typecheck

let orchestrator_schema = import "../schemas/orchestrator.ncl" in

{
  orchestrator | orchestrator_schema.OrchestratorConfig = {
    # Workspace Configuration
    workspace = {
      {%- if workspace_name %}
      name = "{{ workspace_name }}",
      {%- endif %}
      {%- if workspace_path %}
      path = "{{ workspace_path }}",
      {%- endif %}
      {%- if workspace_enabled is defined %}
      enabled = {{ workspace_enabled | lower }},
      {%- endif %}
      {%- if multi_workspace_mode is defined %}
      multi_workspace = {{ multi_workspace_mode | lower }},
      {%- endif %}
    },

    # HTTP Server Configuration
    server = {
      {%- if server_host %}
      host = "{{ server_host }}",
      {%- endif %}
      {%- if server_port %}
      port = {{ server_port }},
      {%- endif %}
      {%- if server_workers %}
      workers = {{ server_workers }},
      {%- endif %}
      {%- if server_keep_alive %}
      keep_alive = {{ server_keep_alive }},
      {%- endif %}
      {%- if server_max_connections %}
      max_connections = {{ server_max_connections }},
      {%- endif %}
      {%- if server_request_timeout %}
      request_timeout = {{ server_request_timeout }},
      {%- endif %}
      {%- if server_graceful_shutdown is defined %}
      graceful_shutdown = {{ server_graceful_shutdown | lower }},
      {%- endif %}
      {%- if server_shutdown_timeout %}
      shutdown_timeout = {{ server_shutdown_timeout }},
      {%- endif %}
    },

    # Storage Configuration
    storage = {
      {%- if storage_backend %}
      backend = "{{ storage_backend }}",
      {%- endif %}
      {%- if storage_path %}
      path = "{{ storage_path }}",
      {%- endif %}
      {%- if storage_cache_enabled is defined %}
      cache = {
        enabled = {{ storage_cache_enabled | lower }},
        {%- if storage_cache_type %}
        type = "{{ storage_cache_type }}",
        {%- endif %}
        {%- if storage_cache_ttl %}
        ttl = {{ storage_cache_ttl }},
        {%- endif %}
        {%- if storage_cache_eviction_policy %}
        eviction_policy = "{{ storage_cache_eviction_policy }}",
        {%- endif %}
      },
      {%- endif %}
    },

    # Queue Configuration
    queue = {
      {%- if queue_max_concurrent_tasks %}
      max_concurrent_tasks = {{ queue_max_concurrent_tasks }},
      {%- endif %}
      {%- if queue_retry_attempts %}
      retry_attempts = {{ queue_retry_attempts }},
      {%- endif %}
      {%- if queue_retry_delay %}
      retry_delay = {{ queue_retry_delay }},
      {%- endif %}
      {%- if queue_task_timeout %}
      task_timeout = {{ queue_task_timeout }},
      {%- endif %}
      {%- if queue_persist is defined %}
      persist = {{ queue_persist | lower }},
      {%- endif %}
      {%- if queue_dead_letter_enabled is defined %}
      dead_letter_queue = {
        enabled = {{ queue_dead_letter_enabled | lower }},
        {%- if queue_dead_letter_max_size %}
        max_size = {{ queue_dead_letter_max_size }},
        {%- endif %}
      },
      {%- endif %}
      {%- if queue_priority_queue is defined %}
      priority_queue = {{ queue_priority_queue | lower }},
      {%- endif %}
      {%- if queue_metrics is defined %}
      metrics = {{ queue_metrics | lower }},
      {%- endif %}
    },

    # Batch Workflow Configuration
    batch = {
      {%- if batch_parallel_limit %}
      parallel_limit = {{ batch_parallel_limit }},
      {%- endif %}
      {%- if batch_operation_timeout %}
      operation_timeout = {{ batch_operation_timeout }},
      {%- endif %}
      {%- if batch_checkpointing_enabled is defined %}
      checkpointing = {
        enabled = {{ batch_checkpointing_enabled | lower }},
        {%- if batch_checkpoint_interval %}
        interval = {{ batch_checkpoint_interval }},
        {%- endif %}
        {%- if batch_checkpoint_max_checkpoints %}
        max_checkpoints = {{ batch_checkpoint_max_checkpoints }},
        {%- endif %}
      },
      {%- endif %}
      {%- if batch_rollback_enabled is defined %}
      rollback = {
        enabled = {{ batch_rollback_enabled | lower }},
        {%- if batch_rollback_strategy %}
        strategy = "{{ batch_rollback_strategy }}",
        {%- endif %}
        {%- if batch_rollback_max_depth %}
        max_rollback_depth = {{ batch_rollback_max_depth }},
        {%- endif %}
      },
      {%- endif %}
      {%- if batch_metrics is defined %}
      metrics = {{ batch_metrics | lower }},
      {%- endif %}
    },

    # Extensions Configuration
    {%- if extensions_auto_load is defined or extensions_oci_registry_url %}
    extensions = {
      {%- if extensions_auto_load is defined %}
      auto_load = {{ extensions_auto_load | lower }},
      {%- endif %}
      {%- if extensions_oci_registry_url %}
      oci_registry_url = "{{ extensions_oci_registry_url }}",
      {%- endif %}
      {%- if extensions_oci_namespace %}
      oci_namespace = "{{ extensions_oci_namespace }}",
      {%- endif %}
      {%- if extensions_discovery_interval %}
      discovery_interval = {{ extensions_discovery_interval }},
      {%- endif %}
      {%- if extensions_max_concurrent %}
      max_concurrent = {{ extensions_max_concurrent }},
      {%- endif %}
      {%- if extensions_timeout %}
      timeout = {{ extensions_timeout }},
      {%- endif %}
      {%- if extensions_sandbox is defined %}
      sandbox = {{ extensions_sandbox | lower }},
      {%- endif %}
    },
    {%- endif %}

    # Monitoring Configuration (optional)
    {%- if monitoring_enabled is defined %}
    monitoring = {
      enabled = {{ monitoring_enabled | lower }},
      {%- if monitoring_metrics_enabled is defined %}
      metrics = {
        enabled = {{ monitoring_metrics_enabled | lower }},
        {%- if monitoring_metrics_interval %}
        interval = {{ monitoring_metrics_interval }},
        {%- endif %}
      },
      {%- endif %}
    },
    {%- endif %}

    # Logging Configuration (optional)
    {%- if logging_level %}
    logging = {
      level = "{{ logging_level }}",
      {%- if logging_format %}
      format = "{{ logging_format }}",
      {%- endif %}
    },
    {%- endif %}
  },
}
