{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hub.omdsh.dev/submission.schema.json",
  "title": "OMDSH Workshop Submission",
  "type": "object",
  "required": ["schema", "operation", "project", "release", "management", "declarations"],
  "additionalProperties": false,
  "properties": {
    "schema": { "const": "omdsh-workshop-submission/v1" },
    "operation": { "enum": ["create-project", "add-release"] },
    "project": {
      "type": "object",
      "required": ["id", "displayName", "summary", "kind", "category", "tags", "repository", "path", "author", "license"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
        "displayName": { "type": "string", "minLength": 1 },
        "summary": { "type": "string", "minLength": 12 },
        "kind": { "enum": ["skill", "mcp", "extension", "channel", "ui", "adapter", "manager", "toolkit"] },
        "category": { "enum": ["workflow", "developer-tools", "channels", "interface", "platform", "safety", "memory", "infrastructure", "fun"] },
        "tags": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "repository": { "type": "string", "pattern": "^https://github\\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/?$" },
        "path": {
          "oneOf": [
            { "type": "null" },
            { "type": "string", "pattern": "^/" }
          ]
        },
        "author": {
          "type": "object",
          "required": ["name", "url"],
          "additionalProperties": false,
          "properties": {
            "name": { "type": "string", "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$" },
            "url": { "type": "string", "format": "uri", "pattern": "^https://github\\.com/" }
          }
        },
        "license": { "type": "string", "minLength": 1 },
        "media": {
          "oneOf": [
            { "type": "null" },
            { "$ref": "#/$defs/media" }
          ]
        }
      }
    },
    "release": {
      "type": "object",
      "required": ["version", "ref", "updatedAt", "channel", "compatibility", "changelog", "capabilities", "profileBundle"],
      "additionalProperties": false,
      "properties": {
        "version": { "type": "string", "minLength": 1 },
        "ref": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "updatedAt": { "type": "string", "format": "date-time" },
        "channel": { "enum": ["stable", "beta", "nightly"] },
        "compatibility": { "type": "string", "minLength": 1 },
        "changelog": { "type": "string", "minLength": 1 },
        "capabilities": {
          "type": "object",
          "required": ["requiresFabric", "deepHook", "restartRequired"],
          "additionalProperties": false,
          "properties": {
            "requiresFabric": { "type": "boolean" },
            "deepHook": { "type": "boolean" },
            "restartRequired": { "type": "boolean" }
          }
        },
        "profileBundle": {
          "oneOf": [
            { "type": "null" },
            {
              "type": "object",
              "required": ["packageName", "spec"],
              "additionalProperties": false,
              "properties": {
                "packageName": {
                  "type": "string",
                  "pattern": "^(?:@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$"
                },
                "spec": {
                  "type": "string",
                  "pattern": "^(?:(?:v)?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?|(?:git\\+https://|https://|github:)[^#\\s]+#[0-9a-f]{40})$"
                }
              }
            }
          ]
        }
      }
    },
    "management": {
      "type": "object",
      "required": ["method", "protocol", "label", "instructions", "source"],
      "additionalProperties": false,
      "properties": {
        "method": { "enum": ["profile-bundle", "repository-plugin", "guided"] },
        "protocol": {
          "enum": ["harness-profile", "harness-repository", "harness-cordis", "third-party"]
        },
        "label": { "type": "string", "minLength": 1 },
        "instructions": { "type": "string", "minLength": 1 },
        "source": {
          "oneOf": [
            { "type": "null" },
            { "type": "string", "minLength": 1 }
          ]
        }
      }
    },
    "declarations": {
      "type": "object",
      "required": ["permissions", "testing", "trustedPublisherRequested", "installScriptsMustRemainDisabled"],
      "additionalProperties": false,
      "properties": {
        "permissions": { "type": "string", "minLength": 1 },
        "testing": { "type": "string", "minLength": 1 },
        "trustedPublisherRequested": { "type": "boolean" },
        "installScriptsMustRemainDisabled": { "const": true }
      }
    }
  },
  "$defs": {
    "media": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": false,
      "properties": {
        "icon": { "$ref": "#/$defs/mediaPath" },
        "cover": { "$ref": "#/$defs/mediaPath" },
        "screenshots": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/mediaPath" }
        }
      }
    },
    "mediaPath": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*\\.(?:png|jpe?g|webp|avif)$"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": { "management": { "properties": { "method": { "const": "profile-bundle" } } } }
      },
      "then": {
        "properties": {
          "release": { "properties": { "profileBundle": { "type": "object" } } },
          "management": { "properties": { "protocol": { "const": "harness-profile" } } }
        }
      },
      "else": {
        "properties": { "release": { "properties": { "profileBundle": { "type": "null" } } } }
      }
    },
    {
      "if": {
        "properties": { "management": { "properties": { "method": { "const": "repository-plugin" } } } }
      },
      "then": {
        "properties": {
          "management": {
            "properties": {
              "protocol": { "const": "harness-repository" },
              "source": {
                "type": "string",
                "pattern": "^github:[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+#[0-9a-f]{40}&path:/[^&\\s]+$"
              }
            }
          }
        }
      },
      "else": {
        "properties": { "management": { "properties": { "source": { "type": "null" } } } }
      }
    },
    {
      "if": {
        "properties": { "management": { "properties": { "method": { "const": "guided" } } } }
      },
      "then": {
        "properties": {
          "management": {
            "properties": {
              "protocol": { "enum": ["harness-cordis", "third-party"] },
              "source": { "type": "null" }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "release": {
            "properties": {
              "capabilities": { "properties": { "deepHook": { "const": true } } }
            }
          }
        }
      },
      "then": {
        "properties": {
          "release": {
            "properties": {
              "capabilities": { "properties": { "requiresFabric": { "const": true } } }
            }
          }
        }
      }
    }
  ]
}
