{
  "$defs": {
    "ApplicationDeletionPolicy": {
      "oneOf": [
        {
          "const": "Foreground",
          "description": "Cascade deletion in the foreground using the Argo CD resources finalizer.",
          "type": "string"
        },
        {
          "const": "Background",
          "description": "Cascade deletion in the background using the Argo CD background finalizer.",
          "type": "string"
        },
        {
          "const": "Orphan",
          "description": "Omit the finalizer and leave workload resources in place.",
          "type": "string"
        }
      ]
    },
    "ArgoCDInstanceSpec": {
      "additionalProperties": false,
      "properties": {
        "catalogApplicationDefaults": {
          "$ref": "#/$defs/CatalogApplicationDefaults",
          "default": {
            "applicationDeletionPolicy": "Foreground",
            "project": "default",
            "selfPrunePolicy": "Confirm",
            "syncPolicy": {
              "syncOptions": [
                "ApplyOutOfSyncOnly=true",
                "ServerSideApply=true"
              ]
            }
          },
          "description": "Default policy for the catalog Applications of targets using this instance."
        },
        "clusterRef": {
          "$ref": "#/$defs/LocalReference",
          "description": "Project-local Cluster containing the Argo CD control plane."
        },
        "namespace": {
          "default": "argocd",
          "description": "Namespace containing Argo CD Applications and AppProjects.",
          "type": "string"
        }
      },
      "required": [
        "clusterRef"
      ],
      "type": "object"
    },
    "CatalogApplicationDefaults": {
      "additionalProperties": false,
      "properties": {
        "annotations": {
          "additionalProperties": {
            "type": "string"
          },
          "description": "Annotations added to generated Applications.",
          "type": "object"
        },
        "applicationDeletionPolicy": {
          "$ref": "#/$defs/ApplicationDeletionPolicy",
          "default": "Foreground",
          "description": "Argo CD Application finalizer policy: foreground cascade, background cascade, or orphan workloads."
        },
        "labels": {
          "additionalProperties": {
            "type": "string"
          },
          "description": "Labels added to generated Applications.",
          "type": "object"
        },
        "project": {
          "default": "default",
          "description": "Argo CD project assigned to generated catalog Applications.",
          "type": "string"
        },
        "selfPrunePolicy": {
          "$ref": "#/$defs/ManagedResourceDeletionPolicy",
          "default": "Confirm",
          "description": "Policy for pruning the catalog Application itself. Confirmation is required by default."
        },
        "syncPolicy": {
          "$ref": "#/$defs/GitOpsSyncPolicy",
          "default": {
            "syncOptions": [
              "ApplyOutOfSyncOnly=true",
              "ServerSideApply=true"
            ]
          },
          "description": "Catalog synchronization policy. Defaults to manual sync with apply-only-out-of-sync and server-side apply."
        }
      },
      "type": "object"
    },
    "GitOpsAutomatedSyncPolicy": {
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "description": "Whether automated sync is enabled. Omission enables it when the automated block is present.",
          "type": [
            "boolean",
            "null"
          ]
        },
        "prune": {
          "default": false,
          "description": "Allow Argo CD to prune resources removed from desired manifests.",
          "type": "boolean"
        },
        "selfHeal": {
          "default": false,
          "description": "Allow Argo CD to repair live drift automatically.",
          "type": "boolean"
        }
      },
      "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"
    },
    "GitOpsSyncPolicy": {
      "additionalProperties": false,
      "properties": {
        "automated": {
          "anyOf": [
            {
              "$ref": "#/$defs/GitOpsAutomatedSyncPolicy"
            },
            {
              "type": "null"
            }
          ],
          "description": "Presence enables automated synchronization unless `enabled` is false."
        },
        "syncOptions": {
          "description": "Argo CD sync options. Generated Applications add `ApplyOutOfSyncOnly=true` and `ServerSideApply=true` unless an option with the same key is supplied.",
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      },
      "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"
    },
    "ManagedResourceDeletionPolicy": {
      "oneOf": [
        {
          "const": "Automatic",
          "description": "Allow pruning or deletion without additional restrictions.",
          "type": "string"
        },
        {
          "const": "Confirm",
          "description": "Require confirmation through the Argo CD Prune or Delete sync option.",
          "type": "string"
        },
        {
          "const": "Retain",
          "description": "Set the Argo CD Prune or Delete sync option to false.",
          "type": "string"
        }
      ]
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Defines an Argo CD control plane and the catalog defaults for its deployment targets.\n\nThis is compiler configuration. Targets sharing an instance must use unambiguous generated Application and AppProject names.\n\n## When needed\n\nDeclare one to configure a shared or remote Argo CD control plane, a different namespace, or shared catalog defaults.\n\n## If omitted\n\nWhen no ArgoCDInstance resources are declared, each target uses an implicit instance in its workload Cluster, in namespace `argocd`, with the catalog defaults. Leave `spec.argocdRef` unset in this case. Once any explicit instance exists, every DeploymentTarget must set `spec.argocdRef.name` to a declared instance.",
  "examples": [
    {
      "apiVersion": "k8s.gitops.nyl/v1",
      "kind": "ArgoCDInstance",
      "metadata": {
        "name": "primary"
      },
      "spec": {
        "clusterRef": {
          "name": "primary"
        },
        "namespace": "argocd"
      }
    }
  ],
  "properties": {
    "apiVersion": {
      "const": "k8s.gitops.nyl/v1",
      "description": "API group and version defining this resource.",
      "type": "string"
    },
    "kind": {
      "const": "ArgoCDInstance",
      "description": "Resource kind within the API group.",
      "type": "string"
    },
    "metadata": {
      "$ref": "#/$defs/GitOpsResourceMetadata",
      "description": "Resource identity and metadata."
    },
    "spec": {
      "$ref": "#/$defs/ArgoCDInstanceSpec",
      "description": "Configuration for this resource."
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "title": "ArgoCDInstance",
  "type": "object"
}
