{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://confighub.github.io/helm-expt/site/review.schema.json",
  "title": "ConfigHub Workshop configuration review",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "const": "workshop.confighub.com/v1alpha1" },
    "kind": { "const": "ConfigurationReview" },
    "metadata": {
      "type": "object",
      "required": ["id", "createdAt"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "createdAt": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "spec": {
      "type": "object",
      "required": ["question", "source", "candidate", "comparison", "assessment", "checks", "finding", "recommendation"],
      "properties": {
        "question": {
          "type": "object",
          "required": ["code", "text"],
          "properties": {
            "code": { "type": "string", "minLength": 1 },
            "text": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        "source": {
          "type": "object",
          "required": ["type", "visibility"],
          "properties": {
            "type": { "enum": ["helm", "aicr", "timoni", "oci", "kubernetes-yaml", "existing-release", "mixed", "unknown"] },
            "visibility": { "enum": ["public", "private"] },
            "identity": { "type": "string" },
            "version": { "type": "string" },
            "valuesSummary": { "type": "string" }
          },
          "additionalProperties": false
        },
        "candidate": { "$ref": "#/$defs/objectSet" },
        "comparison": {
          "type": "object",
          "required": ["status"],
          "properties": {
            "status": { "enum": ["not-supplied", "compared"] },
            "objectSet": { "$ref": "#/$defs/objectSet" },
            "added": { "type": "array", "items": { "type": "string" } },
            "removed": { "type": "array", "items": { "type": "string" } },
            "changed": { "type": "array", "items": { "type": "string" } },
            "unchanged": { "type": "array", "items": { "type": "string" } },
            "noOp": { "type": "array", "items": { "type": "string" } }
          },
          "additionalProperties": false
        },
        "assessment": { "$ref": "#/$defs/assessment" },
        "checks": {
          "type": "object",
          "required": ["method", "scope", "findings", "notChecked", "advisoryReceipts"],
          "properties": {
            "method": { "type": "string", "minLength": 1 },
            "scope": { "type": "string", "minLength": 1 },
            "findings": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["code", "level", "message"],
                "properties": {
                  "code": { "type": "string", "minLength": 1 },
                  "level": { "enum": ["review", "warning", "information"] },
                  "object": { "type": "string" },
                  "message": { "type": "string", "minLength": 1 }
                },
                "additionalProperties": false
              }
            },
            "notChecked": { "type": "array", "items": { "type": "string" } },
            "advisoryReceipts": {
              "type": "array",
              "items": { "$ref": "#/$defs/localAdvisoryReceipt" }
            }
          },
          "additionalProperties": false
        },
        "finding": { "type": "string" },
        "recommendation": { "type": "string", "minLength": 1 },
        "lifecycle": { "type": "object" },
        "catalog": {
          "type": "object",
          "properties": {
            "status": { "enum": ["not-looked-up", "exact", "related", "absent"] },
            "url": { "type": "string" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  },
  "$defs": {
    "assessment": {
      "type": "object",
      "required": ["stages"],
      "properties": {
        "stages": {
          "type": "array",
          "minItems": 4,
          "maxItems": 4,
          "items": { "$ref": "#/$defs/assessmentStage" }
        }
      },
      "additionalProperties": false
    },
    "assessmentStage": {
      "type": "object",
      "required": ["id", "question", "answer", "requiredInputs", "catalogMatchRequired", "sourceIntentRequired", "destinationAccessRequired", "deploymentRequired", "evidenceState", "resultState", "records", "nextAction"],
      "properties": {
        "id": { "enum": ["inspection", "materialization", "destination", "post-deployment"] },
        "question": { "type": "string", "minLength": 1 },
        "answer": { "type": "string", "minLength": 1 },
        "requiredInputs": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
        "catalogMatchRequired": { "type": "boolean" },
        "sourceIntentRequired": { "type": "boolean" },
        "destinationAccessRequired": { "type": "boolean" },
        "deploymentRequired": { "type": "boolean" },
        "evidenceState": { "enum": ["completed", "pending", "not-run", "blocked", "not-applicable"] },
        "resultState": { "enum": ["available", "pass", "watch", "fail", "pending", "not-run", "blocked", "not-applicable"] },
        "records": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "nextAction": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "localAdvisoryReceipt": {
      "type": "object",
      "required": ["authority", "tool", "version", "schemaVersion", "scanTime", "catalogVersion", "patternBundle", "input", "findingCount", "findingIds"],
      "properties": {
        "authority": { "const": "local-advisory" },
        "tool": { "const": "cub-scan" },
        "version": { "type": "string", "minLength": 1 },
        "schemaVersion": { "const": "risk-scan-findings-v1" },
        "scanTime": { "type": "string", "format": "date-time" },
        "catalogVersion": { "type": "string", "minLength": 1 },
        "patternBundle": {
          "type": "object",
          "required": ["schemaVersion", "version", "sourceRepo", "manifestSha256", "catalogSha256"],
          "properties": {
            "schemaVersion": { "const": "bundle-manifest-v1" },
            "version": { "type": "string", "minLength": 1 },
            "sourceRepo": { "type": "string", "minLength": 1 },
            "manifestSha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "catalogSha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
          },
          "additionalProperties": false
        },
        "input": {
          "type": "object",
          "required": ["objectCount", "objectSetSha256"],
          "properties": {
            "objectCount": { "type": "integer", "minimum": 1 },
            "objectSetSha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
          },
          "additionalProperties": false
        },
        "findingCount": { "type": "integer", "minimum": 0 },
        "findingIds": { "type": "array", "items": { "type": "string", "minLength": 1 } }
      },
      "additionalProperties": false
    },
    "objectSet": {
      "type": "object",
      "required": ["name", "sha256", "objectCount", "objects"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "sha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "objectCount": { "type": "integer", "minimum": 0 },
        "objects": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
