{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "RuntimeState",
  "type": "object",
  "properties": {
    "checks": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/CheckRecord"
      }
    },
    "clocks": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/ClockState"
      }
    },
    "current_branch": {
      "type": "string"
    },
    "current_node": {
      "type": "string"
    },
    "items": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/ItemInstance"
      }
    },
    "knowledge": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/KnowledgeRecord"
      }
    },
    "promises": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/Promise"
      }
    },
    "relationship_states": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/RelationshipState"
      }
    },
    "relationships": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/RelationshipAxes"
      },
      "default": {}
    },
    "story_id": {
      "type": "string"
    },
    "world_flags": {
      "type": "object",
      "additionalProperties": {
        "type": "boolean"
      },
      "default": {}
    }
  },
  "required": [
    "story_id",
    "current_node",
    "current_branch"
  ],
  "$defs": {
    "AcquisitionMode": {
      "type": "string",
      "enum": [
        "initial",
        "found",
        "given",
        "borrowed",
        "stolen",
        "returned"
      ]
    },
    "CheckDifficulty": {
      "type": "string",
      "enum": [
        "regular",
        "hard",
        "extreme"
      ]
    },
    "CheckRecord": {
      "type": "object",
      "properties": {
        "action_id": {
          "type": "string"
        },
        "actor": {
          "type": "string"
        },
        "bonus_dice": {
          "type": "integer",
          "format": "int8",
          "maximum": 127,
          "minimum": -128
        },
        "difficulty": {
          "$ref": "#/$defs/CheckDifficulty"
        },
        "id": {
          "type": "string"
        },
        "node_id": {
          "type": "string"
        },
        "pushed_from": {
          "type": [
            "string",
            "null"
          ]
        },
        "result": {
          "$ref": "#/$defs/CheckResult"
        },
        "roll": {
          "type": "integer",
          "format": "uint8",
          "maximum": 255,
          "minimum": 0
        },
        "skill": {
          "type": "string"
        },
        "target": {
          "type": "integer",
          "format": "uint8",
          "maximum": 255,
          "minimum": 0
        }
      },
      "required": [
        "id",
        "action_id",
        "actor",
        "skill",
        "target",
        "difficulty",
        "bonus_dice",
        "roll",
        "result",
        "node_id"
      ]
    },
    "CheckResult": {
      "type": "string",
      "enum": [
        "critical_success",
        "extreme_success",
        "hard_success",
        "success",
        "failure",
        "fumble"
      ]
    },
    "ClockState": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "max": {
          "type": "integer",
          "format": "uint16",
          "maximum": 65535,
          "minimum": 0
        },
        "value": {
          "type": "integer",
          "format": "uint16",
          "maximum": 65535,
          "minimum": 0
        }
      },
      "required": [
        "id",
        "label",
        "value",
        "max"
      ]
    },
    "ItemAcquisition": {
      "type": "object",
      "properties": {
        "at_node": {
          "type": "string"
        },
        "from": {
          "type": [
            "string",
            "null"
          ]
        },
        "mode": {
          "$ref": "#/$defs/AcquisitionMode"
        }
      },
      "required": [
        "mode",
        "at_node"
      ]
    },
    "ItemInstance": {
      "type": "object",
      "properties": {
        "acquisition": {
          "$ref": "#/$defs/ItemAcquisition"
        },
        "condition": {
          "type": "string"
        },
        "holder": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "owner": {
          "type": "string"
        },
        "placement": {
          "$ref": "#/$defs/ItemPlacement"
        },
        "quantity": {
          "type": "integer",
          "format": "uint32",
          "minimum": 0
        },
        "spec_ref": {
          "type": "string"
        },
        "state_tags": {
          "type": "array",
          "default": [],
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "id",
        "spec_ref",
        "owner",
        "holder",
        "placement",
        "quantity",
        "condition",
        "acquisition"
      ]
    },
    "ItemPlacement": {
      "type": "string",
      "enum": [
        "bag",
        "worn",
        "hand",
        "scene",
        "hidden"
      ]
    },
    "KnowledgeCertainty": {
      "type": "string",
      "enum": [
        "suspected",
        "reported",
        "confirmed"
      ]
    },
    "KnowledgeRecord": {
      "type": "object",
      "properties": {
        "certainty": {
          "$ref": "#/$defs/KnowledgeCertainty"
        },
        "fact": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "last_verified_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "learned_at": {
          "type": "string"
        },
        "observer": {
          "type": "string"
        },
        "source": {
          "type": "string"
        },
        "subject": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "id",
        "observer",
        "fact",
        "certainty",
        "source",
        "learned_at"
      ]
    },
    "Promise": {
      "type": "object",
      "properties": {
        "accepted_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "content": {
          "type": "string"
        },
        "created_at": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "promisee": {
          "type": "string"
        },
        "promiser": {
          "type": "string"
        },
        "resolved_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "$ref": "#/$defs/PromiseStatus"
        },
        "weight": {
          "$ref": "#/$defs/PromiseWeight"
        }
      },
      "required": [
        "id",
        "promiser",
        "promisee",
        "content",
        "status",
        "weight",
        "created_at"
      ]
    },
    "PromiseStatus": {
      "type": "string",
      "enum": [
        "proposed",
        "accepted",
        "fulfilled",
        "broken",
        "released",
        "impossible"
      ]
    },
    "PromiseWeight": {
      "type": "string",
      "enum": [
        "minor",
        "major"
      ]
    },
    "RelationshipAxes": {
      "type": "object",
      "properties": {
        "affinity": {
          "type": "integer",
          "format": "int16",
          "maximum": 32767,
          "minimum": -32768
        },
        "attachment": {
          "type": "integer",
          "format": "int16",
          "maximum": 32767,
          "minimum": -32768
        },
        "hope": {
          "type": "integer",
          "format": "int16",
          "maximum": 32767,
          "minimum": -32768
        },
        "intimacy": {
          "type": "integer",
          "format": "int16",
          "maximum": 32767,
          "minimum": -32768
        },
        "respect": {
          "type": "integer",
          "format": "int16",
          "maximum": 32767,
          "minimum": -32768
        },
        "trust": {
          "type": "integer",
          "format": "int16",
          "maximum": 32767,
          "minimum": -32768
        }
      },
      "required": [
        "affinity",
        "trust",
        "hope",
        "respect",
        "intimacy",
        "attachment"
      ]
    },
    "RelationshipState": {
      "type": "object",
      "properties": {
        "active": {
          "type": "boolean"
        },
        "description": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "source_node": {
          "type": "string"
        },
        "tag": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "tag",
        "description",
        "source_node",
        "active"
      ]
    }
  }
}
