{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schema.ontai.dev/v1alpha1/seam-core/InfrastructurePackInstance.json",
  "title": "InfrastructurePackInstance",
  "description": "Records the delivered state of an InfrastructureClusterPack on a target cluster. Owned by seam-core; created by the PackExecutionReconciler after a successful pack-deploy Job. One PackInstance per logical pack per target cluster. Present on both management and tenant clusters. wrapper-schema.md §3.",
  "x-ont-layer": "seam-core",
  "x-ont-stability": "alpha",
  "x-ont-namespace": "seam-tenant-{clusterName}",
  "x-ont-depends-on": ["seam-core/InfrastructureClusterPack"],
  "type": "object",
  "required": ["spec"],
  "properties": {
    "spec": {
      "type": "object",
      "description": "InfrastructurePackInstance specification. Written once at creation by the PackExecutionReconciler.",
      "required": ["clusterPackRef", "targetClusterRef"],
      "properties": {
        "clusterPackRef": {
          "type": "string",
          "description": "Name of the InfrastructureClusterPack CR that was delivered."
        },
        "version": {
          "type": "string",
          "description": "Semantic version of the ClusterPack that was delivered. Copied from ClusterPack.spec.version at creation time."
        },
        "targetClusterRef": {
          "type": "string",
          "description": "Name of the TalosCluster to which this pack was delivered."
        },
        "dependsOn": {
          "type": "array",
          "description": "Names of InfrastructurePackInstance CRs that this instance depends on.",
          "items": {
            "type": "string"
          }
        },
        "dependencyPolicy": {
          "type": "object",
          "description": "Behavior when a declared dependency PackInstance reports drift.",
          "properties": {
            "onDrift": {
              "type": "string",
              "enum": ["Block", "Warn", "Ignore"],
              "description": "Policy when a dependency reports Drifted=True. Default: Warn."
            }
          },
          "additionalProperties": false
        },
        "chartVersion": {
          "type": "string",
          "description": "Version of the Helm chart delivered for this PackInstance. Copied from the ClusterPack at creation time. Absent for kustomize and raw category packs. Decision B."
        },
        "chartURL": {
          "type": "string",
          "description": "URL of the Helm chart repository. Copied from the ClusterPack at creation time. Absent for kustomize and raw category packs. Decision B."
        },
        "chartName": {
          "type": "string",
          "description": "Name of the Helm chart delivered. Copied from the ClusterPack at creation time. Absent for kustomize and raw category packs. Decision B."
        },
        "helmVersion": {
          "type": "string",
          "description": "Version of the Helm SDK used to render the ClusterPack this instance records. Copied from the ClusterPack at creation time. Absent for kustomize and raw category packs. Decision B."
        }
      },
      "additionalProperties": false
    },
    "status": {
      "type": "object",
      "description": "Runtime status. Written by the PackInstanceReconciler and conductor drift loop.",
      "properties": {
        "deliveredAt": {
          "type": "string",
          "format": "date-time",
          "description": "Timestamp when the pack was last confirmed delivered."
        },
        "driftSummary": {
          "type": "string",
          "description": "Human-readable summary of current drift state."
        },
        "upgradeDirection": {
          "type": "string",
          "enum": ["Initial", "Upgrade", "Rollback", "Redeploy"],
          "description": "Direction of the last version transition for this PackInstance. Initial: first deployment. Upgrade: newer ClusterPack version. Rollback: older ClusterPack version. Redeploy: same version reapplied. Set by PackExecutionReconciler via semver comparison."
        },
        "deployedResources": {
          "type": "array",
          "description": "List of Kubernetes resources applied by the pack-deploy job for this PackInstance. Written by PackExecutionReconciler on success. Used by the deletion handler to clean up deployed workload on ClusterPack deletion.",
          "items": {
            "type": "object",
            "required": ["apiVersion", "kind", "name"],
            "properties": {
              "apiVersion": {
                "type": "string",
                "description": "Kubernetes apiVersion (e.g., apps/v1, v1)."
              },
              "kind": {
                "type": "string",
                "description": "Kubernetes resource Kind (e.g., Deployment, Namespace)."
              },
              "namespace": {
                "type": "string",
                "description": "Namespace of the resource. Empty for cluster-scoped resources."
              },
              "name": {
                "type": "string",
                "description": "Resource name."
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
