{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:junexis:schema:release-migration-index:0.1",
  "title": "Deklaracje migracji wydania Junexis 0.1",
  "description": "Indeks deklaracji składników umieszczony w archiwum manifestu objętym podpisanym katalogiem wydania.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "releaseVersion", "rid", "manifestSha256", "declarations"],
  "properties": {
    "schemaVersion": { "const": "junexis.release-migration-index/0.1" },
    "releaseVersion": { "$ref": "#/$defs/semver" },
    "rid": { "enum": ["win-x64", "linux-x64", "osx-arm64"] },
    "manifestSha256": { "$ref": "#/$defs/sha256" },
    "declarations": {
      "type": "array",
      "maxItems": 256,
      "items": { "$ref": "#/$defs/declaration" }
    }
  },
  "$defs": {
    "identifier": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{1,127}$" },
    "semver": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?$" },
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}(?![\\s\\S])" },
    "declaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["component", "fromVersion", "toVersion", "mode", "migrationId"],
      "properties": {
        "component": { "$ref": "#/$defs/identifier" },
        "fromVersion": { "oneOf": [{ "$ref": "#/$defs/semver" }, { "type": "null" }] },
        "toVersion": { "$ref": "#/$defs/semver" },
        "mode": { "enum": ["no-data-change", "migration"] },
        "migrationId": { "oneOf": [{ "$ref": "#/$defs/identifier" }, { "type": "null" }] }
      },
      "allOf": [
        {
          "if": { "properties": { "mode": { "const": "no-data-change" } }, "required": ["mode"] },
          "then": { "properties": { "migrationId": { "type": "null" } } }
        },
        {
          "if": { "properties": { "mode": { "const": "migration" } }, "required": ["mode"] },
          "then": { "properties": { "fromVersion": { "$ref": "#/$defs/semver" }, "migrationId": { "$ref": "#/$defs/identifier" } } }
        }
      ]
    }
  }
}
