{
  "$defs": {
    "Admission": {
      "description": "Whether state-writing runs require a CI deployment admission.",
      "enum": [
        "off",
        "required"
      ],
      "type": "string"
    },
    "DriftRepair": {
      "description": "Whether reconcile repairs drift on its own.\n\nContract: [Drift](../../../../design/orchestration-core.md#drift).",
      "oneOf": [
        {
          "const": "converge",
          "description": "The next reconcile executes drifted units whose recovery policy is\n`converge` again; a drifted unit that is not safe to re-run awaits\napproval.",
          "type": "string"
        },
        {
          "const": "manual",
          "description": "Reconcile repairs no drift by itself: drifted units stay `drifted`\nuntil `nyl reconcile --unit <unit> --reapply --reason <text>`.",
          "type": "string"
        }
      ]
    },
    "EnvironmentGroupSpec": {
      "additionalProperties": false,
      "properties": {
        "admission": {
          "anyOf": [
            {
              "$ref": "#/$defs/Admission"
            },
            {
              "type": "null"
            }
          ],
          "description": "Default `admission` of the members."
        },
        "allowUnprotectedSource": {
          "description": "Default `allowUnprotectedSource` of the members.",
          "type": [
            "boolean",
            "null"
          ]
        },
        "driftRepair": {
          "anyOf": [
            {
              "$ref": "#/$defs/DriftRepair"
            },
            {
              "type": "null"
            }
          ],
          "description": "Default `driftRepair` of the members."
        },
        "environmentSelector": {
          "$ref": "#/$defs/LabelSelector",
          "description": "Matches literal Environment `metadata.labels`. Must not be empty."
        },
        "protectedRefs": {
          "description": "Default `protectedRefs` of the members.",
          "items": {
            "type": "string"
          },
          "type": [
            "array",
            "null"
          ]
        },
        "state": {
          "$ref": "#/$defs/EnvironmentGroupState",
          "default": {},
          "description": "Default state repository of the members."
        },
        "values": {
          "additionalProperties": true,
          "description": "Defaults beneath each member's `values`; the member wins.",
          "type": "object"
        }
      },
      "required": [
        "environmentSelector"
      ],
      "type": "object"
    },
    "EnvironmentGroupState": {
      "additionalProperties": false,
      "description": "The state repository a group's members default to. Refs and paths stay\neach environment's own.",
      "properties": {
        "repository": {
          "anyOf": [
            {
              "$ref": "#/$defs/InlineGitRepository"
            },
            {
              "type": "null"
            }
          ],
          "description": "Inline repository coordinates holding the members' state. Mutually exclusive with `repositoryRef`."
        },
        "repositoryRef": {
          "anyOf": [
            {
              "$ref": "#/$defs/LocalReference"
            },
            {
              "type": "null"
            }
          ],
          "description": "GitRepository holding the members' state. Mutually exclusive with `repository`."
        }
      },
      "type": "object"
    },
    "GitOpsResourceMetadata": {
      "additionalProperties": false,
      "description": "Metadata shared by local GitOps compiler resources.",
      "properties": {
        "labels": {
          "additionalProperties": {
            "type": "string"
          },
          "description": "Literal labels used for organization and target selection.",
          "type": "object"
        },
        "name": {
          "description": "Project-local identity, validated by the resource kind; remains static during discovery.",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "InlineGitRepository": {
      "additionalProperties": false,
      "properties": {
        "publishURL": {
          "description": "Optional Git write URL. Publication uses `repoURL` when omitted.",
          "type": [
            "string",
            "null"
          ]
        },
        "repoURL": {
          "description": "Credential-free Git read URL used by renderers and generated Applications.",
          "type": "string"
        }
      },
      "required": [
        "repoURL"
      ],
      "type": "object"
    },
    "LabelSelector": {
      "additionalProperties": false,
      "properties": {
        "matchLabels": {
          "additionalProperties": {
            "type": "string"
          },
          "description": "Exact label matches, combined with AND. An empty map selects every ApplicationGroup.",
          "type": "object"
        }
      },
      "type": "object"
    },
    "LocalReference": {
      "additionalProperties": false,
      "properties": {
        "name": {
          "description": "Project-local name of the referenced resource; its kind and API group are determined by the containing field.",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Environments that belong together, with configuration they share.\n\nA group selects declared Environments by their literal labels, the labels\n`-l` matches, and names them for `-g`. Its fields are defaults beneath each\nmember's own.\n\n## When needed\n\nTo reconcile several environments with `-g <group>`, or to share state,\nprotected refs, or values among them.\n\n## If omitted\n\nEach Environment carries all of its own configuration.",
  "examples": [
    {
      "apiVersion": "gitops.nyl/v1",
      "kind": "EnvironmentGroup",
      "metadata": {
        "name": "production"
      },
      "spec": {
        "driftRepair": "manual",
        "environmentSelector": {
          "matchLabels": {
            "stage": "production"
          }
        },
        "values": {
          "cluster": "prod-1"
        }
      }
    }
  ],
  "properties": {
    "apiVersion": {
      "const": "gitops.nyl/v1",
      "description": "API group and version defining this resource.",
      "type": "string"
    },
    "kind": {
      "const": "EnvironmentGroup",
      "description": "Resource kind within the API group.",
      "type": "string"
    },
    "metadata": {
      "$ref": "#/$defs/GitOpsResourceMetadata",
      "description": "Resource identity and metadata."
    },
    "spec": {
      "$ref": "#/$defs/EnvironmentGroupSpec",
      "description": "Configuration for this resource."
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "title": "EnvironmentGroup",
  "type": "object"
}
