{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://overseer.studio/schemas/extension/manifest.json",
  "title": "Overseer Extension Manifest",
  "description": "Schema for an extension manifest.json inside an Overseer plugin package",
  "type": "object",
  "required": ["id", "label", "description", "version", "category", "icon", "source"],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string",
      "description": "Reference to this schema"
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "description": "Unique extension identifier within the plugin"
    },
    "label": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable extension name shown in the UI"
    },
    "description": {
      "type": "string",
      "minLength": 1,
      "description": "Short description of the extension"
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+",
      "description": "Extension version in X.Y.Z semver format"
    },
    "category": {
      "type": "string",
      "enum": [
        "Native",
        "Audio",
        "Character Sheets",
        "Combat",
        "Dice",
        "Organization",
        "Reference",
        "VTT",
        "Video",
        "Other"
      ],
      "description": "Extension category used for filtering in the tile picker"
    },
    "icon": {
      "type": "object",
      "required": ["$ref"],
      "additionalProperties": false,
      "properties": {
        "$ref": { "type": "string", "description": "Relative path to the icon file" }
      },
      "description": "Extension icon reference"
    },
    "source": {
      "oneOf": [
        {
          "type": "string",
          "enum": ["webview", "iframe"],
          "description": "Built-in renderer type"
        },
        {
          "type": "object",
          "required": ["$ref"],
          "additionalProperties": false,
          "properties": {
            "$ref": { "type": "string", "description": "Relative path to a source bundle file" }
          },
          "description": "Reference to an external source file"
        }
      ],
      "description": "How the extension content is rendered"
    },
    "author": {
      "type": "string",
      "description": "Author of this extension"
    },
    "visible": {
      "type": "boolean",
      "default": true,
      "description": "Whether the extension appears in the tile picker"
    },
    "transparent": {
      "type": "boolean",
      "default": true,
      "description": "Whether the tile background is transparent"
    },
    "fullScreen": {
      "type": "boolean",
      "default": false,
      "description": "Whether the extension opens in full screen by default"
    },
    "defaultCullable": {
      "type": "boolean",
      "description": "Whether tiles created from this extension are culled by default when off-screen"
    },
    "config": {
      "type": "object",
      "description": "User-configurable fields for this extension"
    },
    "permissions": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "send": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Events this extension is allowed to broadcast"
        },
        "receive": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Events this extension is allowed to listen to"
        }
      },
      "description": "Extension messaging permissions"
    },
    "consumes": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^@[^:]+:[^:]+$",
        "description": "Dataset ID in @pluginScope/pluginName:datasetId format"
      },
      "description": "Datasets this extension reads from"
    },
    "associatedFileTypes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["mimeTypes", "extensions"],
        "additionalProperties": false,
        "properties": {
          "mimeTypes": {
            "type": "array",
            "items": { "type": "string" }
          },
          "extensions": {
            "type": "array",
            "items": { "type": "string" }
          }
        }
      },
      "description": "File types this extension can open"
    },
    "shortcuts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "label"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "label": { "type": "string", "minLength": 1 },
          "description": { "type": "string" },
          "defaultKey": { "type": "string" }
        }
      },
      "description": "Keyboard shortcuts registered by this extension"
    },
    "webview": {
      "type": "object",
      "required": ["src"],
      "additionalProperties": false,
      "properties": {
        "src": {
          "type": "string",
          "minLength": 1,
          "description": "URL or path for the webview content"
        },
        "baseUrl": { "type": "string", "description": "Deprecated: use src" },
        "urlTemplate": { "type": "string", "description": "Deprecated: use src" },
        "injectJavaScript": {
          "type": "string",
          "description": "Relative path to a JS file to inject into the webview"
        }
      },
      "description": "Webview configuration (required when source is \"webview\")"
    },
    "baseUrl": {
      "type": "string",
      "description": "Deprecated: use webview.src"
    }
  }
}
