{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://altheia.local/schemas/altheia_simulator_metric_review_1.0.schema.json",
  "type": "object",
  "required": [
    "schema_version",
    "execution_hash",
    "aggregate_hash",
    "protocol_hash",
    "bindings"
  ],
  "properties": {
    "schema_version": {
      "const": "altheia_simulator_metric_review_1.0"
    },
    "execution_hash": {
      "type": "string",
      "pattern": "^fnv1a-[a-f0-9]{8}$"
    },
    "aggregate_hash": {
      "type": "string",
      "pattern": "^fnv1a-[a-f0-9]{8}$"
    },
    "protocol_hash": {
      "type": "string",
      "pattern": "^fnv1a-[a-f0-9]{8}$"
    },
    "bindings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "metric_id",
          "definition_hash",
          "canonical_dimension_id",
          "dimension_model_hash",
          "status",
          "review"
        ],
        "properties": {
          "metric_id": {
            "type": "string"
          },
          "definition_hash": {
            "type": "string",
            "pattern": "^fnv1a-[a-f0-9]{8}$"
          },
          "canonical_dimension_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "dimension_model_hash": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^fnv1a-[a-f0-9]{8}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "review": {
            "type": "object",
            "properties": {
              "reviewed_by": {
                "type": "string"
              },
              "reviewed_at": {
                "type": "string"
              },
              "source_reference": {
                "type": "string"
              },
              "rationale": {
                "type": "string"
              },
              "human_measurement": {
                "type": "string"
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "status": {
                  "const": "approved"
                }
              },
              "required": [
                "status"
              ]
            },
            "then": {
              "properties": {
                "canonical_dimension_id": {
                  "type": "string",
                  "minLength": 1
                },
                "dimension_model_hash": {
                  "type": "string",
                  "pattern": "^fnv1a-[a-f0-9]{8}$"
                },
                "review": {
                  "required": [
                    "reviewed_by",
                    "reviewed_at",
                    "source_reference",
                    "rationale",
                    "human_measurement"
                  ],
                  "properties": {
                    "reviewed_by": {
                      "minLength": 1
                    },
                    "reviewed_at": {
                      "format": "date-time"
                    },
                    "source_reference": {
                      "minLength": 1
                    },
                    "rationale": {
                      "minLength": 5
                    },
                    "human_measurement": {
                      "minLength": 5
                    }
                  }
                }
              }
            }
          }
        ]
      }
    }
  }
}
