{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://confighub.github.io/helm-expt/site/workshop-result.schema.json",
  "title": "ConfigHub Workshop downloadable result",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "const": "workshop.confighub.com/v1alpha2" },
    "kind": { "const": "WorkshopResult" },
    "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", "assessment", "files", "checks", "findingDecisions", "next"],
      "properties": {
        "question": {
          "type": "object",
          "required": ["code", "text"],
          "properties": {
            "code": { "type": "string", "minLength": 1 },
            "text": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        "source": { "type": "object" },
        "candidate": {
          "type": "object",
          "required": ["content", "objectSet"],
          "properties": {
            "content": {
              "type": "object",
              "required": ["path", "sha256"],
              "properties": {
                "path": { "type": "string", "minLength": 1 },
                "sha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
              },
              "additionalProperties": false
            },
            "objectSet": { "$ref": "#/$defs/objectSetIdentity" }
          },
          "additionalProperties": false
        },
        "assessment": { "$ref": "#/$defs/assessment" },
        "files": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "object",
            "required": ["path", "mediaType", "sha256", "content"],
            "properties": {
              "path": { "type": "string", "minLength": 1 },
              "mediaType": { "type": "string", "minLength": 1 },
              "sha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
              "content": { "type": "string" }
            },
            "additionalProperties": false
          }
        },
        "checks": {
          "type": "object",
          "required": ["completed", "notRun", "advisoryReceipts"],
          "properties": {
            "completed": { "type": "array", "items": { "type": "string" } },
            "notRun": { "type": "array", "items": { "type": "string" } },
            "advisoryReceipts": {
              "type": "array",
              "items": { "$ref": "#/$defs/localAdvisoryReceipt" }
            }
          },
          "additionalProperties": false
        },
        "findingDecisions": {
          "type": "object",
          "required": ["status", "candidateObjectSetSha256", "outcomes"],
          "properties": {
            "status": { "enum": ["not-required", "not-recorded", "recorded"] },
            "candidateObjectSetSha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "record": {
              "type": "object",
              "required": ["path", "sha256", "apiVersion", "kind", "name"],
              "properties": {
                "path": { "type": "string", "minLength": 1 },
                "sha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
                "apiVersion": { "type": "string", "minLength": 1 },
                "kind": { "const": "ConfigurationDecision" },
                "name": { "type": "string", "minLength": 1 }
              },
              "additionalProperties": false
            },
            "outcomes": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["findingId", "decision", "rationale", "controlIds"],
                "properties": {
                  "findingId": { "type": "string", "minLength": 1 },
                  "decision": { "enum": ["unreviewed", "accepted-fix", "approved-exception", "rejected"] },
                  "rationale": { "type": "string", "minLength": 1 },
                  "controlIds": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
                  "exception": {
                    "type": "object",
                    "required": ["appliesTo", "excludes", "reviewBy"],
                    "properties": {
                      "appliesTo": { "type": "array", "items": { "type": "string", "minLength": 1 }, "minItems": 1 },
                      "excludes": { "type": "array", "items": { "type": "string", "minLength": 1 }, "minItems": 1 },
                      "reviewBy": { "type": "string", "format": "date-time" }
                    },
                    "additionalProperties": false
                  }
                },
                "additionalProperties": false
              }
            },
            "managedControls": { "type": "array", "items": { "type": "object" } }
          },
          "additionalProperties": false
        },
        "next": {
          "type": "object",
          "required": ["local", "managed"],
          "properties": {
            "local": { "type": "string", "minLength": 1 },
            "managed": { "type": "string", "minLength": 1 }
          },
          "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
    },
    "objectSetIdentity": {
      "type": "object",
      "required": ["algorithm", "objectCount", "sha256"],
      "properties": {
        "algorithm": { "const": "cub-scan-canonical-json-v1" },
        "objectCount": { "type": "integer", "minimum": 1 },
        "sha256": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
      },
      "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
    }
  },
  "additionalProperties": false
}
