{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hashsigsdocs.sahastasai.com/schemas/evidence-v1.json",
  "title": "HashSigs RHDL evidence manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "canonical_origin",
    "profiles",
    "tiers",
    "records"
  ],
  "properties": {
    "$schema": { "type": "string" },
    "schema_version": { "const": 1 },
    "canonical_origin": { "type": "string", "format": "uri" },
    "profiles": {
      "type": "array",
      "minItems": 2,
      "items": { "$ref": "#/$defs/profile" }
    },
    "tiers": {
      "type": "array",
      "minItems": 6,
      "items": { "$ref": "#/$defs/tier" }
    },
    "records": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/record" }
    }
  },
  "$defs": {
    "identifier": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "compatibility"],
      "properties": {
        "id": { "$ref": "#/$defs/identifier" },
        "label": { "type": "string", "minLength": 1 },
        "compatibility": { "type": "string", "minLength": 1 }
      }
    },
    "tier": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "ordinal", "label", "proves", "nonclaims"],
      "properties": {
        "id": { "$ref": "#/$defs/identifier" },
        "ordinal": { "type": "integer", "minimum": 0 },
        "label": { "type": "string", "minLength": 1 },
        "proves": { "type": "string", "minLength": 1 },
        "nonclaims": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "measurement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "value", "unit", "context"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "value": { "type": ["number", "string"] },
        "unit": { "type": "string", "minLength": 1 },
        "context": { "type": "string", "minLength": 1 }
      }
    },
    "tool": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 }
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "sha256"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "path": {
          "type": "string",
          "description": "Canonical path below docs/evidence; published at the same path below /evidence/.",
          "pattern": "^[a-z0-9][a-z0-9._-]*(?:/[a-z0-9][a-z0-9._-]*)*$"
        },
        "bytes": {
          "type": "integer",
          "minimum": 1,
          "description": "Exact byte length of the canonical artifact."
        },
        "media_type": {
          "type": "string",
          "description": "Lowercase media type without parameters.",
          "pattern": "^[a-z0-9][a-z0-9!#$&^_.+-]*/[a-z0-9][a-z0-9!#$&^_.+-]*$"
        }
      },
      "dependentRequired": {
        "path": ["bytes", "media_type"],
        "bytes": ["path", "media_type"],
        "media_type": ["path", "bytes"]
      }
    },
    "record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "date",
        "status",
        "subject",
        "profile",
        "topology",
        "tier",
        "source_commit",
        "source_dirty",
        "source_path",
        "summary",
        "measurements",
        "tools",
        "artifacts",
        "claims",
        "nonclaims",
        "next_gate"
      ],
      "properties": {
        "id": { "$ref": "#/$defs/identifier" },
        "title": { "type": "string", "minLength": 1 },
        "date": { "type": "string", "format": "date" },
        "status": { "enum": ["passed", "failed", "pending"] },
        "subject": { "enum": ["compatibility", "hash", "signer", "verifier", "integration"] },
        "profile": { "$ref": "#/$defs/identifier" },
        "topology": { "type": "string", "minLength": 1 },
        "tier": { "$ref": "#/$defs/identifier" },
        "source_commit": {
          "anyOf": [
            { "type": "string", "pattern": "^[a-f0-9]{40}$" },
            { "type": "null" }
          ]
        },
        "flow_commit": {
          "type": "string",
          "pattern": "^[a-f0-9]{40}$"
        },
        "source_dirty": { "type": ["boolean", "null"] },
        "source_path": { "type": "string", "pattern": "^[^/]" },
        "summary": { "type": "string", "minLength": 1 },
        "command": { "type": "string", "minLength": 1 },
        "measurements": {
          "type": "array",
          "items": { "$ref": "#/$defs/measurement" }
        },
        "tools": {
          "type": "array",
          "items": { "$ref": "#/$defs/tool" }
        },
        "artifacts": {
          "type": "array",
          "items": { "$ref": "#/$defs/artifact" }
        },
        "claims": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "nonclaims": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 }
        },
        "next_gate": { "type": "string", "minLength": 1 }
      }
    }
  }
}
