{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aitownsquare.org/assets/schema/ats-data-001-v1.1.0.schema.json",
  "title": "AI TownSquare Data — ATS-DATA-001",
  "description": "Structural validation rules for one conformant AI TownSquare dataset: a Node, the Session it hosted, and the nine session-level objects that Session produced. This is the machine-enforceable counterpart to the human-readable specification in schema.json. It validates TYPES, REQUIRED fields, and ENUMS — it does not and cannot validate that an id referenced inside a relationship field (e.g. a Theme's claim_ids) actually exists elsewhere in the dataset. That cross-referential check is a separate concern, enforced by scripts/validate-sessions.js.",
  "type": "object",
  "required": ["schema", "version", "node", "session", "participants", "questions", "claims", "themes", "tensions", "signals", "actions", "brief"],
  "additionalProperties": false,
  "properties": {
    "schema": { "const": "aitownsquare" },
    "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "status": { "type": "string" },
    "node": { "$ref": "#/$defs/Node" },
    "session": { "$ref": "#/$defs/Session" },
    "participants": { "$ref": "#/$defs/Participants" },
    "questions": { "type": "array", "items": { "$ref": "#/$defs/Question" } },
    "claims": { "type": "array", "items": { "$ref": "#/$defs/Claim" } },
    "themes": { "type": "array", "items": { "$ref": "#/$defs/Theme" } },
    "tensions": { "type": "array", "items": { "$ref": "#/$defs/Tension" } },
    "signals": { "type": "array", "items": { "$ref": "#/$defs/Signal" } },
    "actions": { "type": "array", "items": { "$ref": "#/$defs/Action" } },
    "brief": { "$ref": "#/$defs/Brief" }
  },
  "$defs": {
    "SRIPillar": {
      "type": "string",
      "enum": ["GOV", "CIT", "ETH", "ECO", "INF", "FOR"]
    },
    "Phase": {
      "type": "string",
      "enum": ["prime", "complicate", "position", "breakout", "shareback", "synthesize", "capture"]
    },
    "Provenance": {
      "type": "object",
      "required": ["session_id", "phase", "source_type", "source_reference"],
      "additionalProperties": false,
      "properties": {
        "session_id": { "type": "string" },
        "phase": { "$ref": "#/$defs/Phase" },
        "source_type": {
          "type": "string",
          "enum": ["participant_quote", "survey", "facilitator_synthesis", "host_reframe"]
        },
        "source_reference": { "type": "string" }
      }
    },
    "Node": {
      "type": "object",
      "required": ["type", "id", "name", "status"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "node" },
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string" },
        "city": { "type": "string" },
        "country": { "type": "string" },
        "status": { "type": "string", "enum": ["active", "past", "upcoming"] },
        "session_ids": { "type": "array", "items": { "type": "string" } },
        "parent_node_id": { "type": ["string", "null"] }
      }
    },
    "Session": {
      "type": "object",
      "required": ["type", "id", "node_id", "date", "protocol_version"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "session" },
        "id": { "type": "string", "pattern": "^CB-[A-Z]+-[0-9]{3}$" },
        "node_id": { "type": "string" },
        "city": { "type": "string" },
        "location": { "type": "string" },
        "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
        "format": { "type": "string" },
        "catalyst": { "type": "string" },
        "protocol_version": { "type": "string" }
      }
    },
    "Participants": {
      "type": "object",
      "required": ["capacity", "registered", "attended"],
      "additionalProperties": false,
      "properties": {
        "capacity": { "type": "integer", "minimum": 0 },
        "registered": { "type": "integer", "minimum": 0 },
        "attended": { "type": "integer", "minimum": 0 },
        "departed_mid_session": { "type": "integer", "minimum": 0 },
        "surveyed": { "type": "integer", "minimum": 0 },
        "roster": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name", "sector"],
            "additionalProperties": false,
            "properties": {
              "name": { "type": "string" },
              "org_role": { "type": "string" },
              "sector": { "type": "string" },
              "linkedin": { "type": ["string", "null"] }
            }
          }
        }
      }
    },
    "Question": {
      "type": "object",
      "required": ["type", "id", "text", "session_id"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "question" },
        "id": { "type": "string" },
        "text": { "type": "string" },
        "session_id": { "type": "string" }
      }
    },
    "Claim": {
      "type": "object",
      "required": ["type", "id", "text", "sector", "session_id", "provenance"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "claim" },
        "id": { "type": "string" },
        "text": { "type": "string" },
        "speaker": { "type": "string" },
        "org_role": { "type": "string" },
        "sector": { "type": "string" },
        "session_id": { "type": "string" },
        "supports_theme_ids": { "type": "array", "items": { "type": "string" } },
        "contradicts_claim_ids": { "type": "array", "items": { "type": "string" } },
        "provenance": { "$ref": "#/$defs/Provenance" }
      }
    },
    "Theme": {
      "type": "object",
      "required": ["type", "id", "title", "summary", "session_id", "provenance"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "theme" },
        "id": { "type": "string" },
        "title": { "type": "string" },
        "summary": { "type": "string" },
        "session_id": { "type": "string" },
        "sri_pillar_id": { "type": "array", "items": { "$ref": "#/$defs/SRIPillar" } },
        "claim_ids": { "type": "array", "items": { "type": "string" } },
        "contributes_to_signal_ids": { "type": "array", "items": { "type": "string" } },
        "provenance": { "$ref": "#/$defs/Provenance" }
      }
    },
    "Tension": {
      "type": "object",
      "required": ["type", "id", "framing_question", "position_a", "position_b", "resolved", "session_id", "provenance"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "tension" },
        "id": { "type": "string" },
        "framing_question": { "type": "string" },
        "position_a": { "type": "string" },
        "position_b": { "type": "string" },
        "resolved": { "type": "boolean" },
        "session_id": { "type": "string" },
        "explains_gap_in_pillar_id": { "$ref": "#/$defs/SRIPillar" },
        "claim_ids": { "type": "array", "items": { "type": "string" } },
        "generates_action_ids": { "type": "array", "items": { "type": "string" } },
        "provenance": { "$ref": "#/$defs/Provenance" }
      }
    },
    "Signal": {
      "type": "object",
      "required": ["type", "id", "prompt", "scale", "n_responses", "range", "session_id", "provenance"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "signal" },
        "id": { "type": "string" },
        "prompt": { "type": "string" },
        "scale": { "type": "string" },
        "n_responses": { "type": "integer", "minimum": 0 },
        "range": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" },
        "sri_equivalent_range": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" },
        "interpretation": { "type": "string" },
        "pillar_id": { "$ref": "#/$defs/SRIPillar" },
        "session_id": { "type": "string" },
        "provenance": { "$ref": "#/$defs/Provenance" }
      }
    },
    "Action": {
      "type": "object",
      "required": ["type", "id", "text", "owner", "session_id", "provenance"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "action" },
        "id": { "type": "string" },
        "text": { "type": "string" },
        "owner": { "type": "string" },
        "priority_quarter": { "type": ["string", "null"] },
        "related_tension_id": { "type": ["string", "null"] },
        "session_id": { "type": "string" },
        "provenance": { "$ref": "#/$defs/Provenance" }
      }
    },
    "Brief": {
      "type": "object",
      "required": ["type", "id", "url", "published_date", "citation"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "brief" },
        "id": { "type": "string", "pattern": "^CB-[A-Z]+-[0-9]{3}$" },
        "url": { "type": "string" },
        "pdf_url": { "type": "string" },
        "published_date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
        "citation": { "type": "string" },
        "claim_ids": { "type": "array", "items": { "type": "string" } },
        "theme_ids": { "type": "array", "items": { "type": "string" } },
        "tension_ids": { "type": "array", "items": { "type": "string" } },
        "signal_ids": { "type": "array", "items": { "type": "string" } },
        "action_ids": { "type": "array", "items": { "type": "string" } }
      }
    }
  }
}
