{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "emergence/essence.schema.json",
  "title": "Distilled essence record (unverified lane)",
  "type": "object",
  "required": ["id", "status", "lane", "article", "essence", "event_type", "topics", "distillation"],
  "properties": {
    "id": { "type": "string", "pattern": "^ess_[a-f0-9]{12}$" },
    "status": { "const": "unverified" },
    "lane": { "const": "net" },
    "article": {
      "type": "object",
      "required": ["raw_id", "source_id", "url", "title", "date"],
      "properties": {
        "raw_id": { "type": "string" },
        "source_id": { "type": "string" },
        "source_name": { "type": "string" },
        "url": { "type": "string" },
        "title": { "type": "string" },
        "date": { "type": "string" }
      }
    },
    "essence": { "type": "string", "minLength": 1 },
    "principles": { "type": "array", "items": { "type": "string" } },
    "topics": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["topic", "subtopic"],
        "properties": {
          "topic": { "type": "string" },
          "subtopic": { "type": "string" }
        }
      }
    },
    "actors": { "type": "array", "items": { "type": "string" } },
    "locations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "country_code"],
        "properties": {
          "name": { "type": "string" },
          "country_code": { "type": "string", "pattern": "^[A-Z]{2}$" }
        }
      }
    },
    "event_type": { "type": "string" },
    "uncertainty": { "type": "string" },
    "distillation": {
      "type": "object",
      "required": ["model", "prompt_version", "distilled_at"],
      "properties": {
        "model": { "type": "string" },
        "prompt_version": { "type": "string" },
        "distilled_at": { "type": "string" },
        "tokens_in": { "type": ["integer", "null"] },
        "tokens_out": { "type": ["integer", "null"] },
        "cost_usd": { "type": ["number", "null"] }
      }
    },
    "failure": {
      "type": ["object", "null"],
      "description": "set on parse_failure records",
      "properties": {
        "kind": { "const": "parse_failure" },
        "raw": { "type": "string" }
      }
    }
  }
}
