{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://civicdataforge.pages.dev/schemas/portfolio-diff-v1.schema.json",
  "title": "CivicDataForge portfolio diff v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "product_id", "scope_hash", "baseline_coverage", "candidate_coverage", "observed_from", "observed_to", "baseline_receipt_hash", "candidate_receipt_hash", "integrity", "counts", "events", "receipt_hash"],
  "properties": {
    "schema_version": {"const": "civicdataforge.portfolio-diff.v1"},
    "product_id": {"type": "string", "minLength": 1},
    "scope_hash": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
    "baseline_coverage": {"enum": ["bounded", "complete"]},
    "candidate_coverage": {"enum": ["bounded", "complete"]},
    "observed_from": {"type": "string", "format": "date-time"},
    "observed_to": {"type": "string", "format": "date-time"},
    "baseline_receipt_hash": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
    "candidate_receipt_hash": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
    "integrity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "disappearance_inference", "limitations"],
      "properties": {
        "status": {"enum": ["accepted", "partial"]},
        "disappearance_inference": {"enum": ["enabled_complete_scope", "suppressed_bounded_scope", "not_evaluated_no_missing"]},
        "limitations": {"type": "array", "items": {"type": "string"}}
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["appeared", "changed", "disappeared", "missing_suppressed", "total_events"],
      "properties": {
        "appeared": {"type": "integer", "minimum": 0},
        "changed": {"type": "integer", "minimum": 0},
        "disappeared": {"type": "integer", "minimum": 0},
        "missing_suppressed": {"type": "integer", "minimum": 0},
        "total_events": {"type": "integer", "minimum": 0}
      }
    },
    "events": {"type": "array", "items": {"$ref": "change-event-v1.schema.json"}},
    "receipt_hash": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"}
  }
}
