{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dealwithdata.com/schema/item.schema.json",
  "title": "dealwithdata content item",
  "description": "The data contract every content file's frontmatter must satisfy.",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "type", "slug", "title", "summary", "status", "classification", "authors", "scales", "created", "updated", "version"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^dwd_[a-z2-7]{8}$",
      "description": "Permanent identifier. Never changes, never reused."
    },
    "type": {
      "enum": ["concept", "pattern", "implementation", "teardown", "term"],
      "description": "concept = what something is; pattern = a reusable design; implementation = working code/config; teardown = analysis of a standard or tool; term = glossary entry."
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "aliases": {
      "type": "array",
      "items": {"type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"},
      "uniqueItems": true,
      "description": "Former slugs, kept so old links redirect."
    },
    "title": {"type": "string", "minLength": 3, "maxLength": 120},
    "summary": {"type": "string", "minLength": 10, "maxLength": 300, "description": "One or two sentences. Used in listings, feeds, search and llms.txt."},
    "status": {"enum": ["draft", "reviewed", "verified"]},
    "verified_by": {"type": "string", "description": "How the content was verified. Required when status is verified."},
    "classification": {"const": "public"},
    "authors": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name"],
        "properties": {
          "name": {"type": "string"},
          "url": {"type": "string", "format": "uri"},
          "role": {"enum": ["author", "guest", "reviewer"]}
        }
      }
    },
    "assisted_by": {
      "type": "array",
      "items": {"type": "string"},
      "description": "AI systems that drafted or edited this item. Never authors."
    },
    "scales": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"enum": ["personal", "business", "enterprise"]}
    },
    "tags": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
    "terms": {
      "type": "array",
      "items": {"type": "string", "pattern": "^dwd_[a-z2-7]{8}$"},
      "uniqueItems": true,
      "description": "Glossary terms (by id) this item uses."
    },
    "related": {
      "type": "array",
      "items": {"type": "string", "pattern": "^dwd_[a-z2-7]{8}$"},
      "uniqueItems": true
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["title", "url", "accessed"],
        "properties": {
          "title": {"type": "string"},
          "url": {"type": "string", "format": "uri"},
          "accessed": {"type": "string", "format": "date"}
        }
      }
    },
    "as_of": {"type": "string", "format": "date", "description": "For fast-moving topics: the date the facts were last checked."},
    "synonyms": {"type": "array", "items": {"type": "string"}, "description": "Terms only: alternative labels (SKOS altLabel)."},
    "broader": {"type": "array", "items": {"type": "string", "pattern": "^dwd_[a-z2-7]{8}$"}, "description": "Terms only: broader terms (SKOS broader)."},
    "created": {"type": "string", "format": "date"},
    "updated": {"type": "string", "format": "date"},
    "version": {"type": "integer", "minimum": 1, "description": "Bump on any change to meaning, not on typo fixes."}
  },
  "allOf": [
    {
      "if": {"properties": {"status": {"const": "verified"}}},
      "then": {"required": ["verified_by"]}
    },
    {
      "if": {"not": {"properties": {"type": {"const": "term"}}}},
      "then": {"not": {"anyOf": [{"required": ["synonyms"]}, {"required": ["broader"]}]}}
    }
  ]
}
