{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ssx360.com/schemas/ssx360.verification.registry-entry.v2.schema.json",
  "title": "SSX360 verification registry entry v2",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "registry_id",
    "verification_level",
    "holder",
    "subject",
    "scope",
    "criteria_version",
    "status",
    "assessor",
    "verified_on",
    "expires_on",
    "report_sha256",
    "evidence_package_sha256",
    "signature"
  ],
  "allOf": [
    {
      "if": {
        "properties": { "status": { "const": "revoked" } },
        "required": ["status"]
      },
      "then": { "required": ["revocation"] }
    },
    {
      "if": {
        "properties": { "status": { "enum": ["current", "expired"] } },
        "required": ["status"]
      },
      "then": { "not": { "required": ["revocation"] } }
    },
    {
      "if": {
        "properties": { "verification_level": { "const": "level-1" } },
        "required": ["verification_level"]
      },
      "then": { "properties": { "registry_id": { "pattern": "^SSX-L1-[0-9]{4,}$" } } }
    },
    {
      "if": {
        "properties": { "verification_level": { "const": "level-2" } },
        "required": ["verification_level"]
      },
      "then": { "properties": { "registry_id": { "pattern": "^SSX-L2-[0-9]{4,}$" } } }
    },
    {
      "if": {
        "properties": { "verification_level": { "const": "level-3" } },
        "required": ["verification_level"]
      },
      "then": { "properties": { "registry_id": { "pattern": "^SSX-L3-[0-9]{4,}$" } } }
    }
  ],
  "properties": {
    "schema": { "const": "ssx360.verification.registry-entry.v2" },
    "registry_id": { "type": "string", "pattern": "^SSX-L[123]-[0-9]{4,}$" },
    "verification_level": { "enum": ["level-1", "level-2", "level-3"] },
    "holder": { "type": "string", "minLength": 1 },
    "subject": { "type": "string", "minLength": 1 },
    "scope": { "type": "string", "minLength": 1 },
    "criteria_version": { "type": "string", "minLength": 1 },
    "status": { "enum": ["current", "expired", "revoked"] },
    "assessor": { "type": "string", "minLength": 1 },
    "verified_on": { "type": "string", "format": "date" },
    "expires_on": { "type": "string", "format": "date" },
    "report_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "evidence_package_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "revocation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["revoked_on", "reason_code"],
      "properties": {
        "revoked_on": { "type": "string", "format": "date" },
        "reason_code": { "type": "string", "minLength": 1 }
      }
    },
    "signature": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema", "algorithm", "device_id", "public_key", "mode", "signed_at", "value"],
      "properties": {
        "schema": { "const": "matrixscroll.signature.v1" },
        "algorithm": { "const": "Ed25519" },
        "device_id": { "type": "string", "minLength": 1 },
        "public_key": { "type": "string", "contentEncoding": "base64" },
        "mode": { "type": "string", "minLength": 1 },
        "signed_at": { "type": "string", "format": "date-time" },
        "value": { "type": "string", "contentEncoding": "base64" }
      }
    }
  }
}
