{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://iarpg.com/campaign-state.schema.json",
  "title": "IARPG Fictional Campaign State Publication",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "id",
    "release",
    "version",
    "status",
    "updated_utc",
    "purpose",
    "source_dataset",
    "truth_boundary",
    "safety_boundary",
    "fairness_rules",
    "reason_codes",
    "lifecycle_transition_rules",
    "state_dimensions",
    "baseline",
    "scenario_events",
    "campaign_missions",
    "counts"
  ],
  "properties": {
    "$schema": {
      "const": "https://iarpg.com/campaign-state.schema.json"
    },
    "id": {
      "const": "iarpg-fictional-campaign-state-prototype"
    },
    "release": {
      "const": "IARPG-OPS-2"
    },
    "version": {
      "const": "2.0.15-wip"
    },
    "status": {
      "const": "work-in-progress-fictional-prototype"
    },
    "updated_utc": {
      "type": "string",
      "format": "date-time"
    },
    "purpose": {
      "type": "string",
      "minLength": 40
    },
    "source_dataset": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "path",
        "schema",
        "faction_count",
        "relationship_count"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "path": {
          "const": "/alliance-network.json"
        },
        "schema": {
          "const": "/alliance-network.schema.json"
        },
        "faction_count": {
          "const": 12
        },
        "relationship_count": {
          "const": 27
        }
      }
    },
    "truth_boundary": {
      "type": "string",
      "minLength": 40
    },
    "safety_boundary": {
      "type": "string",
      "minLength": 40
    },
    "fairness_rules": {
      "type": "array",
      "minItems": 6,
      "items": {
        "type": "string",
        "minLength": 20
      }
    },
    "reason_codes": {
      "type": "array",
      "minItems": 12,
      "items": {
        "$ref": "#/$defs/reasonCode"
      }
    },
    "lifecycle_transition_rules": {
      "type": "array",
      "minItems": 20,
      "items": {
        "$ref": "#/$defs/transitionRule"
      }
    },
    "state_dimensions": {
      "type": "array",
      "minItems": 7,
      "items": {
        "$ref": "#/$defs/stateDimension"
      }
    },
    "baseline": {
      "$ref": "#/$defs/baseline"
    },
    "scenario_events": {
      "type": "array",
      "minItems": 6,
      "items": {
        "$ref": "#/$defs/scenarioEvent"
      }
    },
    "campaign_missions": {
      "type": "array",
      "minItems": 10,
      "items": {
        "$ref": "#/$defs/campaignMission"
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "factions",
        "relationships",
        "baseline_relationship_versions",
        "scenario_events",
        "response_options",
        "campaign_missions",
        "reason_codes"
      ],
      "properties": {
        "factions": {
          "type": "integer",
          "minimum": 1
        },
        "relationships": {
          "type": "integer",
          "minimum": 1
        },
        "baseline_relationship_versions": {
          "type": "integer",
          "minimum": 1
        },
        "scenario_events": {
          "type": "integer",
          "minimum": 1
        },
        "response_options": {
          "type": "integer",
          "minimum": 1
        },
        "campaign_missions": {
          "type": "integer",
          "minimum": 1
        },
        "reason_codes": {
          "type": "integer",
          "minimum": 1
        }
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]*$"
    },
    "reasonCode": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "description"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]+$"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string",
          "minLength": 20
        }
      }
    },
    "transitionRule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "from",
        "to",
        "requires"
      ],
      "properties": {
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        },
        "requires": {
          "type": "array",
          "minItems": 4,
          "items": {
            "type": "string"
          }
        }
      }
    },
    "stateDimension": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "values",
        "rule"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "values": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "rule": {
          "type": "string",
          "minLength": 15
        }
      }
    },
    "domainPosture": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "domain",
        "cooperation"
      ],
      "properties": {
        "domain": {
          "$ref": "#/$defs/id"
        },
        "cooperation": {
          "enum": [
            "minimal",
            "bounded",
            "formal",
            "integrated",
            "contested",
            "suspended"
          ]
        }
      }
    },
    "relationshipState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "relationship_id",
        "version",
        "effective_turn",
        "lifecycle_stage",
        "domain_postures",
        "burden_distribution",
        "source_dependency",
        "target_dependency",
        "consultation_state",
        "evidence_confidence",
        "community_impact",
        "reason_code",
        "explanation",
        "evidence_event_ids",
        "reversible",
        "supersedes"
      ],
      "properties": {
        "relationship_id": {
          "type": "string",
          "pattern": "^rel-[0-9]{2}$"
        },
        "version": {
          "type": "integer",
          "minimum": 1
        },
        "effective_turn": {
          "type": "integer",
          "minimum": 0
        },
        "lifecycle_stage": {
          "type": "string"
        },
        "domain_postures": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/domainPosture"
          }
        },
        "burden_distribution": {
          "enum": [
            "balanced",
            "source-heavy",
            "target-heavy",
            "contested"
          ]
        },
        "source_dependency": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "target_dependency": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "consultation_state": {
          "enum": [
            "available",
            "requested",
            "active",
            "routine",
            "suspended"
          ]
        },
        "evidence_confidence": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "community_impact": {
          "enum": [
            "beneficial",
            "mixed",
            "strained",
            "harm-risk"
          ]
        },
        "reason_code": {
          "type": "string"
        },
        "explanation": {
          "type": "string",
          "minLength": 20
        },
        "evidence_event_ids": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "reversible": {
          "const": true
        },
        "supersedes": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "evidenceEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "kind",
        "summary",
        "source_class",
        "confidence",
        "contestability"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "kind": {
          "$ref": "#/$defs/id"
        },
        "summary": {
          "type": "string",
          "minLength": 20
        },
        "source_class": {
          "$ref": "#/$defs/id"
        },
        "confidence": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "contestability": {
          "type": "string",
          "minLength": 20
        }
      }
    },
    "baseline": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "campaign_id",
        "turn",
        "relationship_states",
        "evidence_events"
      ],
      "properties": {
        "campaign_id": {
          "$ref": "#/$defs/id"
        },
        "turn": {
          "const": 0
        },
        "relationship_states": {
          "type": "array",
          "minItems": 27,
          "maxItems": 27,
          "items": {
            "$ref": "#/$defs/relationshipState"
          }
        },
        "evidence_events": {
          "type": "array",
          "minItems": 27,
          "maxItems": 27,
          "items": {
            "$ref": "#/$defs/evidenceEvent"
          }
        }
      }
    },
    "consultationDecision": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "participants",
        "decision_rule",
        "decision",
        "recording_rule",
        "dissent"
      ],
      "properties": {
        "participants": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "decision_rule": {
          "type": "string",
          "minLength": 8
        },
        "decision": {
          "type": "string",
          "minLength": 20
        },
        "recording_rule": {
          "type": "string",
          "minLength": 20
        },
        "dissent": {
          "type": "string",
          "minLength": 10
        }
      }
    },
    "setFields": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "lifecycle_stage": {
          "type": "string"
        },
        "burden_distribution": {
          "enum": [
            "balanced",
            "source-heavy",
            "target-heavy",
            "contested"
          ]
        },
        "source_dependency": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "target_dependency": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "consultation_state": {
          "enum": [
            "available",
            "requested",
            "active",
            "routine",
            "suspended"
          ]
        },
        "evidence_confidence": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "community_impact": {
          "enum": [
            "beneficial",
            "mixed",
            "strained",
            "harm-risk"
          ]
        }
      }
    },
    "relationshipChange": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "relationship_id",
        "domain",
        "reason_code",
        "set",
        "domain_posture_updates",
        "explanation",
        "reversal"
      ],
      "properties": {
        "relationship_id": {
          "type": "string",
          "pattern": "^rel-[0-9]{2}$"
        },
        "domain": {
          "$ref": "#/$defs/id"
        },
        "reason_code": {
          "type": "string"
        },
        "set": {
          "$ref": "#/$defs/setFields"
        },
        "domain_posture_updates": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/domainPosture"
          }
        },
        "explanation": {
          "type": "string",
          "minLength": 20
        },
        "reversal": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "eligible",
            "trigger",
            "restores"
          ],
          "properties": {
            "eligible": {
              "const": true
            },
            "trigger": {
              "type": "string",
              "minLength": 20
            },
            "restores": {
              "const": "previous-version"
            }
          }
        }
      }
    },
    "blocResponse": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "faction_id",
        "bloc_name",
        "stance",
        "rationale"
      ],
      "properties": {
        "faction_id": {
          "$ref": "#/$defs/id"
        },
        "bloc_name": {
          "type": "string",
          "minLength": 2
        },
        "stance": {
          "enum": [
            "support",
            "support with limits",
            "support with conditions",
            "support with regret",
            "oppose"
          ]
        },
        "rationale": {
          "type": "string",
          "minLength": 15
        }
      }
    },
    "communityConsequence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "community",
        "likely_effect",
        "safeguard",
        "severity"
      ],
      "properties": {
        "community": {
          "type": "string",
          "minLength": 3
        },
        "likely_effect": {
          "type": "string",
          "minLength": 15
        },
        "safeguard": {
          "type": "string",
          "minLength": 15
        },
        "severity": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        }
      }
    },
    "responseOption": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "summary",
        "consultation_decision",
        "relationship_changes",
        "internal_bloc_responses",
        "affected_community_consequences",
        "correction_path",
        "mission_brief_ids"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "label": {
          "type": "string",
          "minLength": 5
        },
        "summary": {
          "type": "string",
          "minLength": 20
        },
        "consultation_decision": {
          "$ref": "#/$defs/consultationDecision"
        },
        "relationship_changes": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/relationshipChange"
          }
        },
        "internal_bloc_responses": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/blocResponse"
          }
        },
        "affected_community_consequences": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/communityConsequence"
          }
        },
        "correction_path": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "trigger",
            "action"
          ],
          "properties": {
            "trigger": {
              "type": "string",
              "minLength": 15
            },
            "action": {
              "type": "string",
              "minLength": 15
            }
          }
        },
        "mission_brief_ids": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/id"
          }
        }
      }
    },
    "scenarioEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "category",
        "trigger",
        "design_question",
        "affected_relationships",
        "evidence_events",
        "consultation_questions",
        "response_options"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "type": "string",
          "minLength": 5
        },
        "category": {
          "$ref": "#/$defs/id"
        },
        "trigger": {
          "type": "string",
          "minLength": 25
        },
        "design_question": {
          "type": "string",
          "minLength": 25
        },
        "affected_relationships": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string",
            "pattern": "^rel-[0-9]{2}$"
          }
        },
        "evidence_events": {
          "type": "array",
          "minItems": 2,
          "items": {
            "$ref": "#/$defs/evidenceEvent"
          }
        },
        "consultation_questions": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string",
            "minLength": 10
          }
        },
        "response_options": {
          "type": "array",
          "minItems": 3,
          "items": {
            "$ref": "#/$defs/responseOption"
          }
        }
      }
    },
    "campaignMission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "focus",
        "linked_scenarios",
        "factions",
        "brief",
        "objective",
        "starting_evidence",
        "player_decisions",
        "roles",
        "safe_actions",
        "success_conditions",
        "partial_outcome",
        "rights_safeguards",
        "safety_boundary"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "type": "string",
          "minLength": 5
        },
        "focus": {
          "type": "string",
          "minLength": 3
        },
        "linked_scenarios": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "factions": {
          "type": "array",
          "minItems": 2,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "brief": {
          "type": "string",
          "minLength": 20
        },
        "objective": {
          "type": "string",
          "minLength": 20
        },
        "starting_evidence": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "player_decisions": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "roles": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "safe_actions": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "success_conditions": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "partial_outcome": {
          "type": "string",
          "minLength": 15
        },
        "rights_safeguards": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string"
          }
        },
        "safety_boundary": {
          "type": "string",
          "minLength": 20
        }
      }
    }
  }
}
