{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:junexis:schema:platform-variant:0.1",
  "title": "Wariant platformowy składnika Junexis 0.1",
  "description": "Jednoznacznie wiąże logiczny składnik i wersję z artefaktem dla RID, wymaganiami systemu, zależnościami natywnymi i podpisem systemowym.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "component", "version", "rid", "system", "architecture", "artifact", "systemRequirements", "systemSignature"],
  "properties": {
    "schemaVersion": { "const": "junexis.platform-variant/0.1" },
    "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" }
  },
  "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" } } }
      }
    }
  ],
  "$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])" },
    "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"] }
        }
      ]
    }
  }
}
