{
  "type": "object",
  "properties": {
    "record_version": {
      "const": "1.0.0"
    },
    "framework_version": {
      "const": "V1"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "synthetic": {
      "type": "boolean"
    },
    "participant_ref": {
      "type": [
        "string",
        "null"
      ]
    },
    "stage": {
      "enum": [
        "ephemeral",
        "stored",
        "published"
      ]
    },
    "consent": {
      "type": "object",
      "properties": {
        "record_storage": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "publication": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "research": {
          "type": [
            "boolean",
            "null"
          ]
        }
      },
      "required": [
        "record_storage",
        "publication",
        "research"
      ],
      "additionalProperties": false
    },
    "research_use_requested": {
      "type": "boolean"
    },
    "context": {
      "type": "object",
      "properties": {
        "setting": {
          "type": "string"
        },
        "activity": {
          "type": "string"
        },
        "physical_needs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "history_volunteered": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "setting",
        "activity",
        "physical_needs",
        "history_volunteered"
      ],
      "additionalProperties": false
    },
    "perspectives": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "speaker_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "language": {
            "type": "string"
          },
          "account": {
            "type": "string"
          },
          "basis": {
            "enum": [
              "self_report",
              "observation",
              "inference",
              "synthetic_example"
            ]
          },
          "confirmed_by_speaker": {
            "type": [
              "boolean",
              "null"
            ]
          }
        },
        "required": [
          "speaker_ref",
          "language",
          "account",
          "basis",
          "confirmed_by_speaker"
        ],
        "additionalProperties": false
      }
    },
    "core_emotions": {
      "type": "object",
      "properties": {
        "HAPPY": {
          "$ref": "#/$defs/rating"
        },
        "ANGER": {
          "$ref": "#/$defs/rating"
        },
        "SADNESS": {
          "$ref": "#/$defs/rating"
        },
        "OVERWHELMED": {
          "$ref": "#/$defs/rating"
        }
      },
      "required": [
        "HAPPY",
        "ANGER",
        "SADNESS",
        "OVERWHELMED"
      ],
      "additionalProperties": false
    },
    "modifiers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "sensory_input",
              "protective_feeling",
              "other_feeling"
            ]
          },
          "label": {
            "type": "string"
          },
          "rating": {
            "$ref": "#/$defs/rating"
          }
        },
        "required": [
          "id",
          "kind",
          "label",
          "rating"
        ],
        "additionalProperties": false
      }
    },
    "dominance": {
      "type": "object",
      "properties": {
        "basis": {
          "enum": [
            "unknown",
            "participant_reported"
          ]
        },
        "states": {
          "type": "array",
          "items": {
            "enum": [
              "HAPPY",
              "ANGER",
              "SADNESS",
              "OVERWHELMED"
            ]
          },
          "uniqueItems": true
        }
      },
      "required": [
        "basis",
        "states"
      ],
      "additionalProperties": false
    },
    "claims": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "theological_belief",
              "subjective_report",
              "observation",
              "inference",
              "empirical_claim",
              "normative_rule"
            ]
          },
          "statement": {
            "type": "string"
          },
          "source_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "discovery_state": {
            "enum": [
              "TRUE",
              "FALSE",
              "NULL"
            ]
          },
          "support_assessment": {
            "enum": [
              "supports",
              "contradicts",
              "mixed",
              "not_assessed"
            ]
          },
          "ethical_provenance": {
            "enum": [
              "pending",
              "cleared",
              "excluded"
            ]
          },
          "confidence_level": {
            "type": [
              "string",
              "null"
            ]
          },
          "search_scope": {
            "type": [
              "string",
              "null"
            ]
          },
          "alternatives": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "id",
          "kind",
          "statement",
          "source_refs",
          "discovery_state",
          "support_assessment",
          "ethical_provenance",
          "confidence_level",
          "search_scope",
          "alternatives"
        ],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "discovery_state": {
                  "const": "TRUE"
                }
              }
            },
            "then": {
              "properties": {
                "source_refs": {
                  "minItems": 1
                }
              }
            }
          }
        ]
      }
    },
    "proposed_next_step": {
      "type": [
        "string",
        "null"
      ]
    },
    "participant_choice": {
      "enum": [
        "not_asked",
        "accepted",
        "declined",
        "paused"
      ]
    },
    "outcome": {
      "type": [
        "string",
        "null"
      ]
    },
    "model_change_proposal": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "required": [
    "record_version",
    "framework_version",
    "id",
    "timestamp",
    "synthetic",
    "participant_ref",
    "stage",
    "consent",
    "research_use_requested",
    "context",
    "perspectives",
    "core_emotions",
    "modifiers",
    "dominance",
    "claims",
    "proposed_next_step",
    "participant_choice",
    "outcome",
    "model_change_proposal"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Psyon V1 proposed reflection record",
  "description": "Prototype structure, not a clinical assessment. Unknown is null. Independent emotion ratings never have to sum to one.",
  "$comment": "No external collection, publication or action is implemented.",
  "$defs": {
    "rating": {
      "type": "object",
      "properties": {
        "intensity": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        },
        "basis": {
          "enum": [
            "self_report",
            "participant_confirmed",
            "synthetic_example",
            "unknown"
          ]
        }
      },
      "required": [
        "intensity",
        "basis"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "basis": {
                "const": "unknown"
              }
            }
          },
          "then": {
            "properties": {
              "intensity": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "intensity": {
                "type": "number"
              }
            }
          }
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "stage": {
            "enum": [
              "stored",
              "published"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "consent": {
            "properties": {
              "record_storage": {
                "const": true
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "stage": {
            "const": "published"
          }
        }
      },
      "then": {
        "properties": {
          "consent": {
            "properties": {
              "publication": {
                "const": true
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "research_use_requested": {
            "const": true
          }
        }
      },
      "then": {
        "properties": {
          "consent": {
            "properties": {
              "research": {
                "const": true
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "dominance": {
            "properties": {
              "basis": {
                "const": "unknown"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "dominance": {
            "properties": {
              "states": {
                "maxItems": 0
              }
            }
          }
        }
      },
      "else": {
        "properties": {
          "dominance": {
            "properties": {
              "states": {
                "minItems": 1
              }
            }
          }
        }
      }
    }
  ]
}
