{
  "$defs": {
    "ClusterApiContractFrom": {
      "additionalProperties": false,
      "description": "The source and extent of an explicitly borrowed API contract.",
      "properties": {
        "clusterRef": {
          "$ref": "#/$defs/LocalReference",
          "description": "Project-local Cluster providing the contract. References must be acyclic."
        },
        "mode": {
          "$ref": "#/$defs/ClusterApiContractMode",
          "description": "`schemas` borrows CRD schemas; `all` also borrows Kubernetes capabilities."
        }
      },
      "required": [
        "clusterRef",
        "mode"
      ],
      "type": "object"
    },
    "ClusterApiContractMode": {
      "description": "Which parts of a Cluster's API contract are inherited.",
      "enum": [
        "schemas",
        "all"
      ],
      "type": "string"
    },
    "ClusterDestination": {
      "additionalProperties": false,
      "description": "Argo CD's identity for a concrete cluster.",
      "oneOf": [
        {
          "description": "Addresses the destination by its registered Argo CD cluster name.",
          "not": {
            "anyOf": [
              {
                "properties": {
                  "server": {
                    "not": {
                      "type": "null"
                    }
                  }
                },
                "required": [
                  "server"
                ]
              }
            ]
          },
          "properties": {
            "name": {
              "not": {
                "type": "null"
              }
            }
          },
          "required": [
            "name"
          ],
          "title": "name"
        },
        {
          "description": "Addresses the destination by its Kubernetes API server URL.",
          "not": {
            "anyOf": [
              {
                "properties": {
                  "name": {
                    "not": {
                      "type": "null"
                    }
                  }
                },
                "required": [
                  "name"
                ]
              }
            ]
          },
          "properties": {
            "server": {
              "not": {
                "type": "null"
              }
            }
          },
          "required": [
            "server"
          ],
          "title": "server"
        }
      ],
      "properties": {
        "name": {
          "description": "Argo CD registered cluster name. Exactly one of `server` and `name` must be non-null.",
          "type": [
            "string",
            "null"
          ]
        },
        "server": {
          "description": "Kubernetes API server URL. Exactly one of `server` and `name` must be non-null.",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "type": "object"
    },
    "ClusterKubernetesCapabilities": {
      "additionalProperties": false,
      "description": "Kubernetes discovery information used for deterministic offline rendering.",
      "properties": {
        "apiVersions": {
          "description": "API versions exposed to Helm. An empty list is valid for scaffolding; target rendering requires at least one entry. With `vendoredCrds`, entries served by vendored CustomResourceDefinitions are omitted here and added from the snapshot.",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "clusterScopedKinds": {
          "description": "Cluster-scoped kinds as `group/Kind`, with `core` for the core API group, such as `core/Namespace`. Recorded by `nyl capture cluster`; every other kind listed in `apiVersions` is namespaced. Empty means the scope is unknown.",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "kubeVersion": {
          "description": "Kubernetes version exposed to Helm. May be omitted for scaffolding; required for target rendering.",
          "type": [
            "string",
            "null"
          ]
        },
        "vendoredCrds": {
          "description": "Whether CustomResourceDefinitions were vendored by `nyl capture cluster --crds`. Their API versions and scopes then come from the vendored snapshot, and rendering fails while it is missing or stale.",
          "type": "boolean"
        }
      },
      "type": "object"
    },
    "ClusterLiveConfiguration": {
      "additionalProperties": false,
      "description": "Local-only connection settings for live operations against a cluster.",
      "properties": {
        "context": {
          "description": "Local kubeconfig context. Live commands prefer an explicit `--context`, then this value, then the current kubeconfig context.",
          "type": "string"
        }
      },
      "required": [
        "context"
      ],
      "type": "object"
    },
    "ClusterSpec": {
      "additionalProperties": false,
      "else": {
        "properties": {
          "kubernetes": {
            "not": {
              "type": "null"
            }
          }
        },
        "required": [
          "kubernetes"
        ]
      },
      "if": {
        "properties": {
          "apiContractFrom": {
            "properties": {
              "mode": {
                "const": "all"
              }
            },
            "required": [
              "mode"
            ],
            "type": "object"
          }
        },
        "required": [
          "apiContractFrom"
        ]
      },
      "properties": {
        "apiContractFrom": {
          "anyOf": [
            {
              "$ref": "#/$defs/ClusterApiContractFrom"
            },
            {
              "type": "null"
            }
          ],
          "description": "Borrow a declared Cluster's captured API contract. Destination, values, and live settings remain local."
        },
        "destination": {
          "$ref": "#/$defs/ClusterDestination",
          "description": "Exactly one concrete Argo CD destination, identified by server URL or registered cluster name."
        },
        "kubernetes": {
          "anyOf": [
            {
              "$ref": "#/$defs/ClusterKubernetesCapabilities"
            },
            {
              "type": "null"
            }
          ],
          "description": "Committed Kubernetes capabilities for deterministic offline rendering. Required unless apiContractFrom.mode is all; omit when inheriting all capabilities. Target rendering requires an effective version and at least one API version."
        },
        "live": {
          "anyOf": [
            {
              "$ref": "#/$defs/ClusterLiveConfiguration"
            },
            {
              "type": "null"
            }
          ],
          "description": "Local connection settings. Omitted from templates and render hashes."
        },
        "values": {
          "additionalProperties": true,
          "description": "Cluster facts merged recursively with target values; target values win.",
          "type": "object"
        }
      },
      "required": [
        "destination"
      ],
      "then": {
        "properties": {
          "kubernetes": {
            "type": "null"
          }
        }
      },
      "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"
    },
    "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": "Describes a concrete Kubernetes destination and its deterministic rendering capabilities.\n\nCluster values supply reusable facts; target values take precedence. This is compiler configuration and is not emitted as a workload manifest.\n\n## When needed\n\nRequired for every workload destination and every explicitly configured Argo CD control-plane destination in Kubernetes GitOps.\n\n## If omitted\n\nTarget rendering fails if the referenced Cluster is missing. Omitting `DeploymentTarget.spec.clusterRef` selects a Cluster with the target name; it does not create that Cluster or infer its capabilities from kubeconfig.",
  "examples": [
    {
      "apiVersion": "k8s.nyl/v1",
      "kind": "Cluster",
      "metadata": {
        "name": "primary"
      },
      "spec": {
        "destination": {
          "server": "https://kubernetes.default.svc"
        },
        "kubernetes": {
          "apiVersions": [
            "v1",
            "apps/v1"
          ],
          "kubeVersion": "1.31.4"
        }
      }
    }
  ],
  "properties": {
    "apiVersion": {
      "const": "k8s.nyl/v1",
      "description": "API group and version defining this resource.",
      "type": "string"
    },
    "kind": {
      "const": "Cluster",
      "description": "Resource kind within the API group.",
      "type": "string"
    },
    "metadata": {
      "$ref": "#/$defs/GitOpsResourceMetadata",
      "description": "Resource identity and metadata."
    },
    "spec": {
      "$ref": "#/$defs/ClusterSpec",
      "description": "Configuration for this resource."
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "title": "Cluster",
  "type": "object"
}
