{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "global": {
      "type": "object",
      "properties": {
        "imageRegistry": {
          "type": "string"
        },
        "imagePullSecrets": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "image": {
          "type": "object",
          "description": "Global image settings applied to all services unless overridden",
          "properties": {
            "tag": {
              "type": "string",
              "description": "Default image tag for all services (overrides Chart.appVersion)"
            },
            "pullPolicy": {
              "type": "string",
              "enum": ["Always", "IfNotPresent", "Never"],
              "description": "Default image pull policy for all services"
            }
          }
        },
        "azureAd": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "instance": {
              "type": "string"
            },
            "domain": {
              "type": "string"
            },
            "tenantId": {
              "type": "string"
            },
            "clientId": {
              "type": "string"
            },
            "clientSecret": {
              "type": "string"
            },
            "scopes": {
              "type": "string"
            }
          }
        },
        "database": {
          "type": "object",
          "properties": {
            "provider": {
              "type": "string",
              "enum": ["Postgres", "SqlServer"]
            },
            "postgres": {
              "type": "object",
              "properties": {
                "host": {
                  "type": "string"
                },
                "port": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 65535
                },
                "database": {
                  "type": "string"
                },
                "username": {
                  "type": "string"
                },
                "password": {
                  "type": "string"
                },
                "existingSecret": {
                  "type": "string"
                },
                "existingSecretKey": {
                  "type": "string"
                }
              }
            },
            "sqlServer": {
              "type": "object",
              "properties": {
                "connectionString": {
                  "type": "string"
                }
              }
            }
          }
        },
        "rabbitmq": {
          "type": "object",
          "properties": {
            "host": {
              "type": "string"
            },
            "username": {
              "type": "string"
            },
            "password": {
              "type": "string"
            },
            "existingSecret": {
              "type": "string"
            },
            "existingSecretKey": {
              "type": "string"
            },
            "prefetch": {
              "type": "integer",
              "minimum": 1
            },
            "activityExchange": {
              "type": "string"
            },
            "completedExchange": {
              "type": "string"
            },
            "workflowEventsExchange": {
              "type": "string"
            }
          }
        }
      }
    },
    "workflowEngine": {
      "allOf": [
        { "$ref": "#/definitions/service" },
        {
          "type": "object",
          "properties": {
            "runtime": {
              "type": "object",
              "properties": {
                "concurrencyMaxRetries": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Maximum retry attempts for concurrency conflicts"
                },
                "concurrencyBaseDelayMs": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Base delay in milliseconds between retries"
                },
                "concurrencyJitterMs": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "Random jitter added to retry delays"
                }
              }
            },
            "tenantSettings": {
              "type": "object",
              "properties": {
                "cacheDurationMinutes": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "How long to cache tenant settings"
                },
                "fallbackToDefaults": {
                  "type": "boolean",
                  "description": "Whether to use defaults when TenantRegistry is unavailable"
                }
              }
            },
            "leaderElection": {
              "type": "object",
              "properties": {
                "defaultLeaseDurationMinutes": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Default leadership lease duration in minutes"
                },
                "retryIntervalSeconds": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "How often to retry acquiring leadership"
                }
              }
            },
            "workflowTimeout": {
              "type": "object",
              "properties": {
                "checkIntervalMinutes": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "How often to check for timed-out workflows"
                },
                "leaseDurationMinutes": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Leadership lease duration for timeout checks"
                }
              }
            },
            "workflowCleanup": {
              "type": "object",
              "properties": {
                "checkIntervalMinutes": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "How often to run cleanup (in minutes)"
                },
                "batchSize": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Max workflows to delete per tenant per run"
                },
                "leaseDurationMinutes": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Leadership lease duration for cleanup"
                }
              }
            }
          }
        }
      ]
    },
    "aiAssistant": {
      "$ref": "#/definitions/service"
    },
    "activityRegistry": {
      "$ref": "#/definitions/service"
    },
    "definitionStore": {
      "$ref": "#/definitions/service"
    },
    "workflowLogging": {
      "$ref": "#/definitions/service"
    },
    "connectionStore": {
      "$ref": "#/definitions/service"
    },
    "tenantRegistry": {
      "$ref": "#/definitions/service"
    },
    "frontendWeb": {
      "$ref": "#/definitions/service"
    }
  },
  "definitions": {
    "service": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "replicaCount": {
          "type": "integer",
          "minimum": 0
        },
        "image": {
          "type": "object",
          "properties": {
            "repository": {
              "type": "string"
            },
            "tag": {
              "type": "string"
            },
            "pullPolicy": {
              "type": "string",
              "enum": ["Always", "IfNotPresent", "Never"]
            }
          }
        },
        "service": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["ClusterIP", "NodePort", "LoadBalancer"]
            },
            "port": {
              "type": "integer",
              "minimum": 1,
              "maximum": 65535
            }
          }
        },
        "ingress": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "className": {
              "type": "string"
            },
            "annotations": {
              "type": "object"
            },
            "hosts": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "host": {
                    "type": "string"
                  },
                  "paths": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string"
                        },
                        "pathType": {
                          "type": "string",
                          "enum": ["Prefix", "Exact", "ImplementationSpecific"]
                        }
                      }
                    }
                  }
                }
              }
            },
            "tls": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "secretName": {
                    "type": "string"
                  },
                  "hosts": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "resources": {
          "type": "object",
          "properties": {
            "limits": {
              "type": "object",
              "properties": {
                "cpu": {
                  "type": "string"
                },
                "memory": {
                  "type": "string"
                }
              }
            },
            "requests": {
              "type": "object",
              "properties": {
                "cpu": {
                  "type": "string"
                },
                "memory": {
                  "type": "string"
                }
              }
            }
          }
        },
        "autoscaling": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "minReplicas": {
              "type": "integer",
              "minimum": 1
            },
            "maxReplicas": {
              "type": "integer",
              "minimum": 1
            },
            "targetCPUUtilizationPercentage": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "targetMemoryUtilizationPercentage": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        },
        "nodeSelector": {
          "type": "object"
        },
        "tolerations": {
          "type": "array"
        },
        "affinity": {
          "type": "object"
        },
        "extraEnv": {
          "type": "array"
        },
        "extraVolumeMounts": {
          "type": "array"
        },
        "extraVolumes": {
          "type": "array"
        }
      }
    }
  }
}
