{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:rightmenu:plugin-manifest:1.5",
  "title": "RightMenu Plugin Manifest API v1.5",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "name",
    "description",
    "version",
    "apiVersion",
    "runtime",
    "permissions",
    "actions",
    "uiContributions",
    "files"
  ],
  "properties": {
    "schemaVersion": { "const": 1 },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)+$"
    },
    "name": { "type": "string", "minLength": 1, "maxLength": 128 },
    "description": { "type": "string", "minLength": 1, "maxLength": 512 },
    "localizedDescriptions": { "$ref": "#/$defs/localizedDescriptions" },
    "version": {
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)$"
    },
    "apiVersion": { "const": "1.5" },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "entrypoint"],
      "properties": {
        "kind": { "const": "javascript" },
        "entrypoint": { "$ref": "#/$defs/safePath" }
      }
    },
    "permissions": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/permission" }
    },
    "actions": {
      "type": "array",
      "minItems": 1,
      "maxItems": 64,
      "items": { "$ref": "#/$defs/action" }
    },
    "uiContributions": {
      "type": "array",
      "maxItems": 8,
      "items": { "$ref": "#/$defs/uiContribution" }
    },
    "files": {
      "type": "array",
      "minItems": 1,
      "maxItems": 128,
      "items": { "$ref": "#/$defs/file" }
    }
  },
  "$defs": {
    "capability": {
      "type": "string",
      "maxLength": 128,
      "pattern": "^[a-z][a-zA-Z0-9-]*(?:\\.[a-z][a-zA-Z0-9-]*)+$"
    },
    "localID": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]*$"
    },
    "safePath": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?!/)(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\\\)(?!.*//).+$"
    },
    "localeMap": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 32,
      "propertyNames": { "type": "string", "minLength": 1, "maxLength": 35 },
      "additionalProperties": { "type": "string", "minLength": 1 }
    },
    "localizedDescriptions": {
      "allOf": [
        { "$ref": "#/$defs/localeMap" },
        { "additionalProperties": { "type": "string", "minLength": 1, "maxLength": 512 } }
      ]
    },
    "localizedTitles": {
      "allOf": [
        { "$ref": "#/$defs/localeMap" },
        { "additionalProperties": { "type": "string", "minLength": 1, "maxLength": 128 } }
      ]
    },
    "permission": {
      "type": "object",
      "additionalProperties": false,
      "required": ["capability", "reason"],
      "properties": {
        "capability": { "$ref": "#/$defs/capability" },
        "reason": { "type": "string", "minLength": 1, "maxLength": 1024 },
        "localizedReasons": {
          "allOf": [
            { "$ref": "#/$defs/localeMap" },
            { "additionalProperties": { "type": "string", "minLength": 1, "maxLength": 1024 } }
          ]
        }
      }
    },
    "requiredCapabilities": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/capability" }
    },
    "booleanTitleState": {
      "type": "object",
      "additionalProperties": false,
      "required": ["capability", "trueTitle"],
      "properties": {
        "capability": { "$ref": "#/$defs/capability" },
        "trueTitle": { "type": "string", "minLength": 1, "maxLength": 128 },
        "localizedTrueTitles": { "$ref": "#/$defs/localizedTitles" }
      }
    },
    "action": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "requiredCapabilities"],
      "properties": {
        "id": { "$ref": "#/$defs/localID" },
        "title": { "type": "string", "minLength": 1, "maxLength": 128 },
        "finderContexts": {
          "type": "array",
          "minItems": 1,
          "maxItems": 2,
          "uniqueItems": true,
          "items": { "enum": ["selection", "container"] }
        },
        "finderLocations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1,
          "uniqueItems": true,
          "items": { "const": "desktop" }
        },
        "localizedTitles": { "$ref": "#/$defs/localizedTitles" },
        "booleanTitleState": { "$ref": "#/$defs/booleanTitleState" },
        "requiredCapabilities": { "$ref": "#/$defs/requiredCapabilities" }
      },
      "allOf": [
        {
          "if": { "required": ["finderLocations"] },
          "then": {
            "required": ["finderContexts"],
            "properties": { "finderContexts": { "const": ["container"] } }
          }
        }
      ]
    },
    "contentSize": {
      "type": "object",
      "additionalProperties": false,
      "required": ["width", "height"],
      "properties": {
        "width": { "type": "integer", "minimum": 320, "maximum": 1440 },
        "height": { "type": "integer", "minimum": 240, "maximum": 1080 }
      }
    },
    "windowPresentation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "titleVisibility": { "enum": ["visible", "hidden"] },
        "initialContentSize": { "$ref": "#/$defs/contentSize" },
        "minimumContentSize": { "$ref": "#/$defs/contentSize" },
        "miniaturizable": { "type": "boolean" }
      }
    },
    "uiContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "resource", "title", "requiredCapabilities"],
      "properties": {
        "id": { "$ref": "#/$defs/localID" },
        "kind": { "enum": ["window", "panel"] },
        "resource": { "$ref": "#/$defs/safePath" },
        "title": { "type": "string", "minLength": 1, "maxLength": 128 },
        "windowPresentation": { "$ref": "#/$defs/windowPresentation" },
        "requiredCapabilities": { "$ref": "#/$defs/requiredCapabilities" }
      }
    },
    "file": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "byteCount", "sha256"],
      "properties": {
        "path": { "$ref": "#/$defs/safePath" },
        "byteCount": { "type": "integer", "minimum": 0, "maximum": 16777216 },
        "sha256": { "type": "string", "pattern": "^[0-9a-fA-F]{64}$" }
      }
    }
  },
  "x-rightmenu-runtime-validation": [
    "IDs, capabilities, and paths must be unique in their respective arrays.",
    "Every requiredCapabilities entry must be declared in permissions.",
    "Every declared API v1.5 permission must be referenced by an action or UI contribution.",
    "The runtime entrypoint and UI resources must be declared in files.",
    "Declared byte counts, SHA-256 values, total size, filesystem entry type, and minimum window size relationships are verified by rightmenu-pluginctl doctor."
  ]
}
