{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.sommatic.ai/schemas/git-sync/environment.schema.json",
  "title": "Sommatic environment file (environments/<name>.json)",
  "description": "Values that change per installation. Resource files use @@env.NAME@@, @@ref.<key>@@ and @@secret.NAME@@ tokens; Sommatic resolves them on sync, on the server.",
  "type": "object",
  "required": ["name", "branch", "variables", "resources", "secrets"],
  "properties": {
    "name": { "type": "string", "description": "Environment name; the connection in Sommatic points to it." },
    "description": { "type": "string" },
    "branch": { "type": "string", "description": "Branch the installation of this environment reads." },
    "variables": {
      "type": "object",
      "description": "NAME → value for @@env.NAME@@ tokens (credential ids, hosts, provider ids, flags).",
      "additionalProperties": { "type": "string" }
    },
    "resources": {
      "type": "object",
      "description": "Logical key → physical id of the resource in this installation. Used by @@ref.<key>@@ and to know which record each file updates.",
      "additionalProperties": { "type": "string" }
    },
    "secrets": {
      "type": "object",
      "description": "Never the value itself: where Sommatic reads it on the server.",
      "additionalProperties": {
        "type": "object",
        "required": ["from"],
        "properties": {
          "from": {
            "enum": ["live", "credential"],
            "description": "live: keep the value the live resource already has at the same JSON path; credential: read a Sommatic credential."
          },
          "id": { "type": "string", "description": "Credential id when from = credential." }
        },
        "additionalProperties": false
      }
    }
  }
}
