{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:junexis:schema:platform-release-catalog:0.2",
  "title": "Podpisany wieloplatformowy katalog wydań Junexis 0.2",
  "description": "Katalog M19 wiążący logiczne składniki z dokładnymi wariantami RID, wymaganiami i podpisami systemowymi.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "channel", "issuedAt", "expiresAt", "entries", "algorithm", "keyId", "signature"],
  "properties": {
    "schemaVersion": { "const": "junexis.platform-release-catalog/0.2" },
    "channel": { "enum": ["dev", "preview", "stable"] },
    "issuedAt": { "$ref": "#/$defs/timestamp" },
    "expiresAt": { "$ref": "#/$defs/timestamp" },
    "entries": {
      "type": "array",
      "minItems": 1,
      "maxItems": 12288,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/entry" }
    },
    "algorithm": { "const": "ecdsa-p256-sha256-der" },
    "keyId": { "$ref": "#/$defs/keyId" },
    "signature": { "type": "string", "minLength": 1, "contentEncoding": "base64" }
  },
  "$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])" },
    "keyId": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
    "timestamp": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["format", "url", "sizeBytes", "sha256"],
      "properties": {
        "format": { "enum": ["zip", "tar.gz", "pkg", "vsix", "nupkg"] },
        "url": { "type": "string", "pattern": "^https://[^\\s]+$" },
        "sizeBytes": { "type": "integer", "minimum": 1 },
        "sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "nativeDependency": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "abi"],
      "properties": {
        "id": { "$ref": "#/$defs/identifier" },
        "version": { "type": "string", "minLength": 1, "maxLength": 128 },
        "abi": { "type": "string", "minLength": 1, "maxLength": 128 }
      }
    },
    "systemRequirements": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minimumOsVersion", "nativeDependencies"],
      "properties": {
        "minimumOsVersion": { "type": "string", "minLength": 1, "maxLength": 64 },
        "nativeDependencies": {
          "type": "array",
          "maxItems": 128,
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/nativeDependency" }
        }
      }
    },
    "systemSignature": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "state"],
      "properties": {
        "kind": { "enum": ["authenticode", "linux-package", "apple-developer-id"] },
        "state": { "enum": ["required", "verified"] },
        "publisher": { "type": "string", "minLength": 1, "maxLength": 256 },
        "signatureSha256": { "$ref": "#/$defs/sha256" }
      },
      "allOf": [
        {
          "if": { "properties": { "state": { "const": "verified" } }, "required": ["state"] },
          "then": { "required": ["publisher", "signatureSha256"] }
        }
      ]
    },
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "component", "version", "rid", "system", "architecture", "artifact",
        "systemRequirements", "systemSignature", "provenanceSha256", "sbomSha256",
        "minimumSupportedVersion", "revoked"
      ],
      "properties": {
        "component": { "$ref": "#/$defs/identifier" },
        "version": { "$ref": "#/$defs/semver" },
        "rid": { "enum": ["win-x64", "linux-x64", "osx-arm64"] },
        "system": { "enum": ["windows", "linux", "macos"] },
        "architecture": { "enum": ["x64", "arm64"] },
        "artifact": { "$ref": "#/$defs/artifact" },
        "systemRequirements": { "$ref": "#/$defs/systemRequirements" },
        "systemSignature": { "$ref": "#/$defs/systemSignature" },
        "provenanceSha256": { "$ref": "#/$defs/sha256" },
        "sbomSha256": { "$ref": "#/$defs/sha256" },
        "minimumSupportedVersion": { "$ref": "#/$defs/semver" },
        "revoked": { "type": "boolean" }
      },
      "oneOf": [
        {
          "properties": {
            "rid": { "const": "win-x64" },
            "system": { "const": "windows" },
            "architecture": { "const": "x64" },
            "systemSignature": { "properties": { "kind": { "const": "authenticode" } } }
          }
        },
        {
          "properties": {
            "rid": { "const": "linux-x64" },
            "system": { "const": "linux" },
            "architecture": { "const": "x64" },
            "systemSignature": { "properties": { "kind": { "const": "linux-package" } } }
          }
        },
        {
          "properties": {
            "rid": { "const": "osx-arm64" },
            "system": { "const": "macos" },
            "architecture": { "const": "arm64" },
            "systemSignature": { "properties": { "kind": { "const": "apple-developer-id" } } }
          }
        }
      ]
    }
  }
}
