{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/business-requirements.schema.json",
  "title": "Business requirements registry assertion",
  "description": "Closed pilot assertion form. The canonical string is only a projection of rule → norm_template modality=duty; observations from the official register and the verification checklist, as well as heuristic candidates, are represented by separate types and do not substitute for it.",
  "$comment": "DECISION-0109",
  "oneOf": [
    {"$ref": "#/$defs/CanonicalRequirement"},
    {"$ref": "#/$defs/DeonticCandidate"},
    {"$ref": "#/$defs/OfficialObservation"},
    {"$ref": "#/$defs/ChecklistObservation"}
  ],
  "$defs": {
    "StableId": {
      "type": "string",
      "minLength": 1,
      "pattern": "^urn:"
    },
    "Digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "Date": {
      "type": "string",
      "format": "date",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "Anchor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["fragment", "contentHash"],
      "properties": {
        "fragment": {"$ref": "#/$defs/StableId"},
        "contentHash": {"$ref": "#/$defs/Digest"}
      }
    },
    "Bearer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "businessBearerStatus"],
      "properties": {
        "type": {"$ref": "#/$defs/StableId"},
        "businessBearerStatus": {
          "type": "string",
          "enum": ["proven", "conditional", "unknown"]
        }
      }
    },
    "Window": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "start", "end", "startInclusive", "endInclusive"],
      "properties": {
        "kind": {"const": "interval"},
        "start": {},
        "end": {},
        "startInclusive": {"type": "boolean"},
        "endInclusive": {"type": "boolean"}
      }
    },
    "Goal": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "window"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": ["achievement", "maintenance", "forbearance"]
        },
        "window": {"$ref": "#/$defs/Window"}
      }
    },
    "Lifecycle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["editions", "parameterRows"],
      "properties": {
        "editions": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "parameterRows": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        }
      }
    },
    "OkedMapping": {
      "type": "object",
      "additionalProperties": false,
      "required": ["mappingStatus"],
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^[0-9]{2,5}$"
        },
        "mappingStatus": {
          "type": "string",
          "enum": ["mapped", "conditional", "not_conditioned", "unknown"]
        }
      },
      "allOf": [
        {
          "if": {"properties": {"mappingStatus": {"enum": ["mapped", "conditional"]}}},
          "then": {"required": ["code"]}
        }
      ]
    },
    "Sanction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["not_mapped", "no_sanction", "mapped"]
        },
        "sanctionIds": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "mappingKind": {
          "type": "string",
          "enum": ["direct", "conditional", "mixed"]
        },
        "offencePredicateIds": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "articleIds": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "mappingReasons": {
          "type": "array",
          "items": {"type": "string", "minLength": 1},
          "uniqueItems": true
        },
        "reason": {"type": "string", "minLength": 1},
        "reviewedScope": {"type": "string", "minLength": 1}
      },
      "allOf": [
        {
          "if": {"properties": {"status": {"const": "mapped"}}},
          "then": {
            "required": ["sanctionIds", "mappingKind", "offencePredicateIds", "articleIds", "mappingReasons"],
            "properties": {
              "sanctionIds": {"minItems": 1},
              "offencePredicateIds": {"minItems": 1},
              "articleIds": {"minItems": 1},
              "mappingReasons": {"minItems": 1}
            }
          }
        },
        {
          "if": {"properties": {"status": {"enum": ["not_mapped", "no_sanction"]}}},
          "then": {"required": ["reason", "reviewedScope"]}
        }
      ]
    },
    "Checklist": {
      "type": "object",
      "additionalProperties": false,
      "required": ["items", "mappingStatus"],
      "properties": {
        "items": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "mappingStatus": {
          "type": "string",
          "enum": ["mapped", "partial", "unmapped", "ambiguous", "out_of_scope"]
        }
      }
    },
    "MachineEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["interpretationGroups", "judgmentPoints", "deadlineFindings", "liveness", "activationScenarios", "twoSidedDates"],
      "properties": {
        "interpretationGroups": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "judgmentPoints": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "deadlineFindings": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "liveness": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["ACTIVE", "SATISFIED", "VIOLATED", "REQUIRES_JUDGMENT"]
          },
          "uniqueItems": true
        },
        "activationScenarios": {
          "type": "array",
          "minItems": 1,
          "items": {"type": "string", "minLength": 1},
          "uniqueItems": true
        },
        "twoSidedDates": {
          "type": "array",
          "items": {"$ref": "#/$defs/Date"},
          "uniqueItems": true
        }
      }
    },
    "OfficialState": {
      "type": "object",
      "additionalProperties": false,
      "required": ["presence", "snapshotId"],
      "properties": {
        "presence": {
          "type": "string",
          "enum": ["present", "excluded", "not_observed", "unknown"]
        },
        "snapshotId": {"type": "string", "minLength": 1}
      }
    },
    "CanonicalRequirement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assertionType", "requirementId", "activationRules", "bearer", "goal", "anchors", "lifecycle", "semanticHash", "sourceFidelity", "oked", "sanction", "checklist", "machineEvidence", "official"],
      "properties": {
        "assertionType": {"const": "canonical"},
        "requirementId": {"$ref": "#/$defs/StableId"},
        "activationRules": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "bearer": {"$ref": "#/$defs/Bearer"},
        "goal": {"$ref": "#/$defs/Goal"},
        "anchors": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/Anchor"}
        },
        "lifecycle": {"$ref": "#/$defs/Lifecycle"},
        "semanticHash": {"$ref": "#/$defs/Digest"},
        "sourceFidelity": {
          "type": "string",
          "enum": ["official_bytes", "pinned_unofficial_copy", "abstract_only", "pinned_editorial_reconstruction", "authored_exposition"]
        },
        "oked": {
          "type": "array",
          "items": {"$ref": "#/$defs/OkedMapping"}
        },
        "sanction": {"$ref": "#/$defs/Sanction"},
        "checklist": {"$ref": "#/$defs/Checklist"},
        "machineEvidence": {"$ref": "#/$defs/MachineEvidence"},
        "official": {"$ref": "#/$defs/OfficialState"}
      }
    },
    "DeonticCandidate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assertionType", "ruleId", "headPredicate", "anchors", "semanticHash", "reason"],
      "properties": {
        "assertionType": {"const": "DEONTIC_CANDIDATE"},
        "ruleId": {"$ref": "#/$defs/StableId"},
        "headPredicate": {"$ref": "#/$defs/StableId"},
        "anchors": {
          "type": "array",
          "items": {"$ref": "#/$defs/Anchor"}
        },
        "semanticHash": {"$ref": "#/$defs/Digest"},
        "reason": {"type": "string", "minLength": 1}
      }
    },
    "OfficialObservation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assertionType", "observationId", "snapshotId", "presence", "sourceUrl", "contentHash"],
      "properties": {
        "assertionType": {"const": "official-observed"},
        "observationId": {"type": "string", "minLength": 1},
        "snapshotId": {"type": "string", "minLength": 1},
        "presence": {
          "type": "string",
          "enum": ["present", "excluded", "not_observed", "unknown"]
        },
        "sourceUrl": {
          "type": "string",
          "format": "uri",
          "pattern": "^https?://[^\\s]+$"
        },
        "contentHash": {"$ref": "#/$defs/Digest"}
      }
    },
    "ChecklistKey": {
      "type": "object",
      "additionalProperties": false,
      "required": ["actId", "appendix", "editionId", "controlProfile", "itemId"],
      "properties": {
        "actId": {"type": "string", "minLength": 1},
        "appendix": {"type": "integer", "minimum": 2, "maximum": 4},
        "editionId": {"$ref": "#/$defs/StableId"},
        "controlProfile": {"type": "string", "minLength": 1},
        "itemId": {"$ref": "#/$defs/StableId"}
      }
    },
    "ChecklistObservation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assertionType", "itemId", "checklistKey", "anchor", "legalReferences", "mappingStatus"],
      "properties": {
        "assertionType": {"const": "checklist-observed"},
        "itemId": {"$ref": "#/$defs/StableId"},
        "checklistKey": {"$ref": "#/$defs/ChecklistKey"},
        "anchor": {"$ref": "#/$defs/Anchor"},
        "legalReferences": {
          "type": "array",
          "items": {"type": "string", "minLength": 1},
          "uniqueItems": true
        },
        "mappedRequirements": {
          "type": "array",
          "items": {"$ref": "#/$defs/StableId"},
          "uniqueItems": true
        },
        "mappingStatus": {
          "type": "string",
          "enum": ["mapped", "unmapped", "ambiguous", "out_of_scope"]
        },
        "reason": {"type": "string", "minLength": 1}
      },
      "allOf": [
        {
          "if": {"properties": {"mappingStatus": {"const": "mapped"}}},
          "then": {"required": ["mappedRequirements"]},
          "else": {"required": ["reason"]}
        }
      ]
    }
  }
}
