{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thewizardnexus.github.io/AX/data/schema/catalog-v2.schema.json",
  "title": "Arcane Exchange Catalog v2",
  "description": "The AX-owned discovery contract for a source-served Arcane listing catalog with type, maturity, and access signals.",
  "type": "object",
  "required": ["schemaVersion", "catalog", "apps"],
  "properties": {
    "schemaVersion": { "const": 2 },
    "catalog": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "name": { "type": "string" },
        "description": { "type": "string" },
        "generatedAt": { "type": "string", "format": "date-time" }
      }
    },
    "apps": {
      "type": "array",
      "items": { "$ref": "#/$defs/app" }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
    },
    "webUrl": {
      "type": "string",
      "pattern": "^(?!.*\\\\)(?:https?://(?![^/?#]*@)[^/?#\\s]+(?:[/?#][^\\s]*)?|(?!(?:[A-Za-z][A-Za-z0-9+.-]*:|//))(?:(?:\\.{0,2}/)(?:[^\\s?#][^\\s]*)?|[^/\\s?#][^\\s]*))$"
    },
    "publisher": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "url": { "$ref": "#/$defs/webUrl" }
      }
    },
    "links": {
      "type": "object",
      "properties": {
        "site": { "$ref": "#/$defs/webUrl" },
        "repository": { "$ref": "#/$defs/webUrl" },
        "manifest": { "$ref": "#/$defs/webUrl" },
        "documentation": { "$ref": "#/$defs/webUrl" }
      },
      "anyOf": [
        { "required": ["site"] },
        { "required": ["repository"] },
        { "required": ["documentation"] }
      ]
    },
    "app": {
      "type": "object",
      "required": ["id", "displayName", "summary", "status", "listingType", "maturity", "access", "publisher", "categories", "links"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "displayName": { "type": "string" },
        "summary": { "type": "string" },
        "description": { "type": "string" },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$"
        },
        "status": { "enum": ["available", "preview", "planned"] },
        "listingType": { "enum": ["app", "platform", "library", "developer-tool", "sdk", "infrastructure"] },
        "maturity": { "enum": ["released", "development", "research", "incubating", "foundation", "prototype"] },
        "access": { "enum": ["public", "source-available", "by-request", "restricted"] },
        "publisher": { "$ref": "#/$defs/publisher" },
        "categories": {
          "type": "array",
          "items": { "type": "string" }
        },
        "capabilities": {
          "type": "array",
          "items": { "type": "string" }
        },
        "mark": { "type": "string" },
        "accent": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" },
        "iconUrl": { "$ref": "#/$defs/webUrl" },
        "links": { "$ref": "#/$defs/links" }
      }
    }
  }
}
