{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.mentenaz-server.com/forge/v1/extensions/schema.json",
  "title": "ExtensionSchema",
  "type": "object",
  "required": [
    "id",
    "name",
    "version",
    "author",
    "description",
    "icon",
    "dock"
  ],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "string" },
    "name": { "type": "string" },
    "version": { "type": "string" },
    "author": { "type": "string" },
    "description": { "type": "string" },
    "icon": {
      "type": "object",
      "required": ["path"],
      "additionalProperties": false,
      "properties": {
        "path": { "type": "string" }
      }
    },
    "dock": {
      "type": "string",
      "enum": ["left", "right", "bottom", "floating", "none"]
    },
    "activationEvents": {
      "type": "array",
      "items": { "type": "string" }
    },
    "secrets": {
      "type": "array",
      "items": { "type": "string" }
    },
    "bindings": {
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/BindingDefinition" }
    },
    "actions": {
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/ActionDefinition" }
    },
    "backend": { "$ref": "#/$defs/BackendDefinition" },
    "components": {
      "type": "array",
      "items": { "$ref": "#/$defs/ComponentNode" }
    }
  },
  "$defs": {
    "RefreshOn": {
      "oneOf": [
        { "const": "activate" },
        {
          "type": "object",
          "required": ["type", "seconds"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "interval" },
            "seconds": { "type": "integer", "minimum": 5 }
          }
        }
      ]
    },
    "BindingDefinition": {
      "oneOf": [
        {
          "type": "object",
          "required": ["type", "action"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "action" },
            "action": { "type": "string" },
            "refreshOn": { "$ref": "#/$defs/RefreshOn" }
          }
        },
        {
          "type": "object",
          "required": ["type", "path"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "fileRead" },
            "path": { "type": "string" },
            "jqFilter": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["type", "key"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "env" },
            "key": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["type", "value"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "computed" },
            "value": { "type": "string" }
          }
        }
      ]
    },
    "ActionDefinition": {
      "oneOf": [
        {
          "type": "object",
          "required": ["type", "command"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "terminal" },
            "command": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["type", "endpoint"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "github" },
            "endpoint": { "type": "string" },
            "resultBinding": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["type", "url"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "http" },
            "url": { "type": "string" },
            "method": { "type": "string" },
            "resultBinding": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["type", "capability"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "forge" },
            "capability": { "type": "string" },
            "resultBinding": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": ["type", "steps"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "chain" },
            "steps": { "type": "array", "items": { "type": "string" } },
            "continueOnError": { "type": "boolean" }
          }
        },
        {
          "type": "object",
          "required": ["type", "function"],
          "additionalProperties": false,
          "properties": {
            "type": { "const": "backend" },
            "function": { "type": "string" },
            "resultBinding": { "type": "string" }
          }
        }
      ]
    },
    "BackendFunctionArg": {
      "type": "object",
      "required": ["name", "type"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string" },
        "type": { "type": "string" }
      }
    },
    "BackendFunction": {
      "type": "object",
      "required": ["name", "args"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string" },
        "args": {
          "type": "array",
          "items": { "$ref": "#/$defs/BackendFunctionArg" }
        }
      }
    },
    "BackendDefinition": {
      "type": "object",
      "required": ["path", "functions"],
      "additionalProperties": false,
      "properties": {
        "path": { "type": "string" },
        "functions": {
          "type": "array",
          "items": { "$ref": "#/$defs/BackendFunction" }
        }
      }
    },
    "ComponentNode": {
      "oneOf": [
        { "$ref": "#/$defs/SectionNode" },
        { "$ref": "#/$defs/SeparatorNode" },
        { "$ref": "#/$defs/StatusRowNode" },
        { "$ref": "#/$defs/BadgeNode" },
        { "$ref": "#/$defs/MetricRowNode" },
        { "$ref": "#/$defs/LinkRowNode" },
        { "$ref": "#/$defs/CodeBlockNode" },
        { "$ref": "#/$defs/OutputTailNode" },
        { "$ref": "#/$defs/ButtonNode" },
        { "$ref": "#/$defs/TextFieldNode" },
        { "$ref": "#/$defs/ToggleNode" },
        { "$ref": "#/$defs/SelectFieldNode" },
        { "$ref": "#/$defs/ListNode" },
        { "$ref": "#/$defs/ProgressBarNode" }
      ]
    },
    "SectionNode": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "Section" },
        "label": { "type": "string" },
        "collapsible": { "type": "boolean" },
        "defaultOpen": { "type": "boolean" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/ComponentNode" }
        }
      }
    },
    "SeparatorNode": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "Separator" }
      }
    },
    "StatusRowNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "StatusRow" },
        "label": { "type": "string" },
        "binding": { "type": "string" },
        "status": { "type": "string", "enum": ["success", "warning", "error"] }
      }
    },
    "BadgeNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "Badge" },
        "label": { "type": "string" },
        "color": {
          "type": "string",
          "enum": ["purple", "green", "red", "yellow"]
        }
      }
    },
    "MetricRowNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "MetricRow" },
        "label": { "type": "string" },
        "binding": { "type": "string" },
        "unit": { "type": "string" }
      }
    },
    "LinkRowNode": {
      "type": "object",
      "required": ["id", "type", "label", "url"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "LinkRow" },
        "label": { "type": "string" },
        "url": { "type": "string" }
      }
    },
    "CodeBlockNode": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "CodeBlock" },
        "binding": { "type": "string" }
      }
    },
    "OutputTailNode": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "OutputTail" },
        "binding": { "type": "string" },
        "maxLines": { "type": "integer" }
      }
    },
    "ButtonNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "Button" },
        "label": { "type": "string" },
        "action": { "type": "string" },
        "variant": {
          "type": "string",
          "enum": ["primary", "secondary", "danger", "ghost"]
        }
      }
    },
    "TextFieldNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "TextField" },
        "label": { "type": "string" },
        "placeholder": { "type": "string" },
        "multiline": { "type": "boolean" }
      }
    },
    "ToggleNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "Toggle" },
        "label": { "type": "string" },
        "default": { "type": "boolean" }
      }
    },
    "SelectFieldNode": {
      "type": "object",
      "required": ["id", "type", "label"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "SelectField" },
        "label": { "type": "string" },
        "options": { "type": "array", "items": { "type": "string" } },
        "default": { "type": "string" }
      }
    },
    "ListNode": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "List" },
        "binding": { "type": "string" },
        "itemTemplate": { "$ref": "#/$defs/ComponentNode" },
        "emptyText": { "type": "string" }
      }
    },
    "ProgressBarNode": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "const": "ProgressBar" },
        "label": { "type": "string" },
        "binding": { "type": "string" }
      }
    }
  }
}
