{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.hoodbuybutton.com/lore/schema.json",
  "title": "Buy Button Lore Database",
  "type": "object",
  "required": [
    "schemaVersion",
    "updatedAt",
    "event",
    "sources",
    "timeline",
    "glossary",
    "motifs",
    "grammar",
    "rights"
  ],
  "properties": {
    "$schema": { "type": "string" },
    "schemaVersion": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "updatedAt": { "type": "string", "format": "date" },
    "title": { "type": "string" },
    "description": { "type": "string" },
    "scope": {
      "type": "object",
      "required": ["includes", "excludes"],
      "properties": {
        "includes": { "type": "array", "items": { "type": "string" } },
        "excludes": { "type": "array", "items": { "type": "string" } }
      }
    },
    "methodology": { "type": "array", "items": { "type": "string" } },
    "event": {
      "type": "object",
      "required": ["id", "date", "summary", "affectedSecurities", "primarySourceIds"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "date": { "type": "string", "format": "date" },
        "summary": { "type": "string" },
        "affectedSecurities": { "type": "array", "items": { "type": "string" } },
        "canonicalTerms": { "type": "array", "items": { "type": "string" } },
        "primarySourceIds": { "$ref": "#/$defs/sourceIds" }
      }
    },
    "sources": {
      "type": "array",
      "minItems": 20,
      "items": {
        "type": "object",
        "required": ["id", "title", "url", "publisher", "type", "authority", "reusePolicy"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "title": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "publisher": { "type": "string" },
          "publishedAt": { "type": ["string", "null"] },
          "type": { "enum": ["primary-record", "community-post", "meme-index", "news", "glossary"] },
          "authority": { "enum": ["primary", "contemporaneous", "reference", "retrospective"] },
          "reusePolicy": { "enum": ["public-record", "link-only"] },
          "notes": { "type": "string" }
        }
      }
    },
    "timeline": {
      "type": "array",
      "minItems": 10,
      "items": { "$ref": "#/$defs/referencedEntry" }
    },
    "glossary": {
      "type": "array",
      "minItems": 25,
      "items": {
        "allOf": [
          { "$ref": "#/$defs/referencedEntry" },
          {
            "type": "object",
            "required": ["term", "category", "definition", "loreContext"],
            "properties": {
              "term": { "type": "string" },
              "aliases": { "type": "array", "items": { "type": "string" } },
              "category": { "type": "string" },
              "definition": { "type": "string" },
              "loreContext": { "type": "string" }
            }
          }
        ]
      }
    },
    "motifs": {
      "type": "array",
      "minItems": 20,
      "items": {
        "allOf": [
          { "$ref": "#/$defs/referencedEntry" },
          {
            "type": "object",
            "required": ["title", "category", "setup", "punchline", "meaning", "visualGrammar", "remixHooks", "reusePolicy"],
            "properties": {
              "title": { "type": "string" },
              "canonicalLine": { "type": "string" },
              "aliases": { "type": "array", "items": { "type": "string" } },
              "category": { "type": "string" },
              "originDate": { "type": ["string", "null"] },
              "originPlatform": { "type": "string" },
              "setup": { "type": "string" },
              "punchline": { "type": "string" },
              "meaning": { "type": "string" },
              "visualGrammar": { "type": "string" },
              "remixHooks": { "type": "array", "items": { "type": "string" } },
              "toneTags": { "type": "array", "items": { "type": "string" } },
              "riskFlags": { "type": "array", "items": { "type": "string" } },
              "reusePolicy": { "enum": ["link-only", "original-remix"] }
            }
          }
        ]
      }
    },
    "grammar": {
      "type": "array",
      "minItems": 5,
      "items": {
        "type": "object",
        "required": ["id", "label", "description", "formula", "examples", "sourceIds"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "label": { "type": "string" },
          "description": { "type": "string" },
          "formula": { "type": "string" },
          "examples": { "type": "array", "items": { "type": "string" } },
          "sourceIds": { "$ref": "#/$defs/sourceIds" }
        }
      }
    },
    "rights": {
      "type": "object",
      "required": ["databaseLicense", "sourceMedia", "quotationPolicy", "takedownContact"],
      "properties": {
        "databaseLicense": { "type": "string" },
        "sourceMedia": { "type": "string" },
        "quotationPolicy": { "type": "string" },
        "takedownContact": { "type": "string", "format": "email" }
      }
    }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
    "sourceIds": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/id" } },
    "referencedEntry": {
      "type": "object",
      "required": ["id", "sourceIds"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "date": { "type": "string" },
        "title": { "type": "string" },
        "summary": { "type": "string" },
        "type": { "type": "string" },
        "sourceIds": { "$ref": "#/$defs/sourceIds" }
      }
    }
  }
}
