{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hogarmas.net/article-50-portfolio/diff-schema.json",
  "title": "H/M Article 50 Portfolio Declaration Diff",
  "description": "Descriptive comparison of two valid portfolio snapshots. It does not infer cause, actor, semantic impact or compliance improvement.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "ruleset",
    "baseline",
    "candidate",
    "summary",
    "added",
    "removed",
    "changed",
    "limitations"
  ],
  "properties": {
    "schema": {
      "const": "hm.article50-portfolio-diff.v1"
    },
    "ruleset": {
      "const": "2026-07-29.1"
    },
    "baseline": {
      "$ref": "#/$defs/portfolioReference"
    },
    "candidate": {
      "$ref": "#/$defs/portfolioReference"
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "added",
        "removed",
        "changed",
        "unchanged"
      ],
      "properties": {
        "added": {
          "$ref": "#/$defs/count"
        },
        "removed": {
          "$ref": "#/$defs/count"
        },
        "changed": {
          "$ref": "#/$defs/count"
        },
        "unchanged": {
          "$ref": "#/$defs/count"
        }
      }
    },
    "added": {
      "type": "array",
      "maxItems": 250,
      "items": {
        "$ref": "#/$defs/systemReference"
      }
    },
    "removed": {
      "type": "array",
      "maxItems": 250,
      "items": {
        "$ref": "#/$defs/systemReference"
      }
    },
    "changed": {
      "type": "array",
      "maxItems": 250,
      "items": {
        "$ref": "#/$defs/systemChange"
      }
    },
    "limitations": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "causeInferred",
        "actorAttributed",
        "complianceChangeCertified",
        "semanticImpactDetermined"
      ],
      "properties": {
        "causeInferred": {
          "const": false
        },
        "actorAttributed": {
          "const": false
        },
        "complianceChangeCertified": {
          "const": false
        },
        "semanticImpactDetermined": {
          "const": false
        }
      }
    }
  },
  "$defs": {
    "count": {
      "type": "integer",
      "minimum": 0
    },
    "portfolioReference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "portfolioName",
        "systems"
      ],
      "properties": {
        "portfolioName": {
          "type": "string",
          "maxLength": 120
        },
        "systems": {
          "$ref": "#/$defs/count"
        }
      }
    },
    "systemReference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "systemId",
        "systemName",
        "owner"
      ],
      "properties": {
        "systemId": {
          "type": "string"
        },
        "systemName": {
          "type": "string"
        },
        "owner": {
          "type": "string"
        }
      }
    },
    "stateChange": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "before",
        "after"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "before": {
          "type": "string"
        },
        "after": {
          "type": "string"
        }
      }
    },
    "metadataChange": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "field",
        "before",
        "after"
      ],
      "properties": {
        "field": {
          "type": "string",
          "enum": [
            "systemName",
            "owner",
            "lane",
            "implementationDate"
          ]
        },
        "before": {},
        "after": {}
      }
    },
    "systemChange": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "systemId",
        "systemName",
        "obligationChanges",
        "evidenceChanges",
        "metadataChanges"
      ],
      "properties": {
        "systemId": {
          "type": "string"
        },
        "systemName": {
          "type": "string"
        },
        "obligationChanges": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/stateChange"
          }
        },
        "evidenceChanges": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/stateChange"
          }
        },
        "metadataChanges": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/metadataChange"
          }
        }
      }
    }
  }
}
