{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/concept-rule-alignment-report.schema.json",
  "type": "object",
  "properties": {
    "format": {
      "const": "arxo.concept-rule-alignment.report/0.1"
    },
    "profile": {
      "enum": [
        "lean-stacks-conditional-rules/0.1",
        "isabelle-order-conditional-rules/0.1",
        "lean-order-conditional-rules/0.1"
      ]
    },
    "policy": {
      "type": "object",
      "properties": {
        "format": {
          "const": "arxo.concept-rule-alignment.policy/0.1"
        },
        "profile": {
          "enum": [
            "lean-stacks-conditional-rules/0.1",
            "isabelle-order-conditional-rules/0.1",
            "lean-order-conditional-rules/0.1"
          ]
        },
        "enabled": {
          "type": "boolean"
        },
        "package": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            },
            "namespace": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "name",
            "version",
            "namespace"
          ],
          "additionalProperties": false
        },
        "source_project": {
          "type": "string",
          "minLength": 1
        },
        "target_packages": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "interpretation_basis": {
          "const": "declared_mapping_assumption"
        },
        "interpretation_hash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "projection_hash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        }
      },
      "required": [
        "format",
        "profile",
        "enabled",
        "package",
        "source_project",
        "target_packages",
        "interpretation_basis",
        "interpretation_hash",
        "projection_hash"
      ],
      "additionalProperties": false
    },
    "policy_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "validator_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "previous_hash": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "sources": {
      "type": "object",
      "properties": {
        "native": {
          "type": "object",
          "properties": {
            "project": {
              "type": "string",
              "minLength": 1
            },
            "revision": {
              "type": "string",
              "minLength": 1
            },
            "input_hash": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "mapping_hash": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            }
          },
          "required": [
            "project",
            "revision",
            "input_hash",
            "mapping_hash"
          ],
          "additionalProperties": false
        },
        "targets": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "version": {
                "type": "string",
                "minLength": 1
              },
              "namespace": {
                "type": "string",
                "minLength": 1
              },
              "content_hash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              }
            },
            "required": [
              "version",
              "namespace",
              "content_hash"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "native",
        "targets"
      ],
      "additionalProperties": false
    },
    "discovery": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "targets": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          }
        },
        "channel": {
          "const": "declared_mapping_and_rule_structure"
        },
        "complete": {
          "const": true
        },
        "source_declarations": {
          "type": "integer",
          "minimum": 0
        },
        "target_rules": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "source",
        "targets",
        "channel",
        "complete",
        "source_declarations",
        "target_rules"
      ],
      "additionalProperties": false
    },
    "decisions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "source": {
            "type": "string",
            "minLength": 1
          },
          "target": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "relation": {
            "enum": [
              "conditional_rule_implementation",
              "definition_equivalence"
            ]
          },
          "direction": {
            "const": "source_to_target_under_interpretation"
          },
          "output": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "parameters": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "type_symbol": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "id",
                "type_symbol"
              ],
              "additionalProperties": false
            }
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "status": {
            "enum": [
              "accepted",
              "review",
              "revoked"
            ]
          },
          "conditions": {
            "type": "object",
            "properties": {
              "interpretation_basis": {
                "const": "declared_mapping_assumption"
              },
              "interpretation_hash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "source_shape": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "types": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "premises": {
                        "type": "array",
                        "items": {
                          "type": "array",
                          "prefixItems": [
                            {
                              "type": "string",
                              "minLength": 1
                            },
                            {
                              "type": "array",
                              "items": {
                                "type": "integer",
                                "minimum": 0
                              }
                            }
                          ],
                          "items": false,
                          "minItems": 2,
                          "maxItems": 2
                        }
                      },
                      "head": {
                        "type": "array",
                        "prefixItems": [
                          {
                            "type": "string",
                            "minLength": 1
                          },
                          {
                            "type": "array",
                            "items": {
                              "type": "integer",
                              "minimum": 0
                            }
                          }
                        ],
                        "items": false,
                        "minItems": 2,
                        "maxItems": 2
                      },
                      "premise_mode": {
                        "enum": [
                          "established",
                          "supported"
                        ],
                        "description": "Premise semantics; legacy reports without this field used established."
                      }
                    },
                    "required": [
                      "types",
                      "premises",
                      "head"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "all_source_conditions_retained": {
                "const": true
              },
              "semantic_equivalence_proved": {
                "const": false
              }
            },
            "required": [
              "interpretation_basis",
              "interpretation_hash",
              "source_shape",
              "all_source_conditions_retained",
              "semantic_equivalence_proved"
            ],
            "additionalProperties": false
          },
          "alternatives": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "target": {
                  "type": "string",
                  "minLength": 1
                },
                "reason": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "target",
                "reason"
              ],
              "additionalProperties": false
            }
          },
          "evidence": {
            "type": "object",
            "properties": {
              "source": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "declaration": {
                      "type": "string",
                      "minLength": 1
                    },
                    "anchor": {
                      "type": "string",
                      "minLength": 1
                    },
                    "document": {
                      "type": "string",
                      "minLength": 1
                    },
                    "document_hash": {
                      "type": "string",
                      "pattern": "^sha256:[0-9a-f]{64}$"
                    },
                    "start": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "end": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "locator": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "declaration",
                    "anchor",
                    "document",
                    "document_hash",
                    "start",
                    "end",
                    "locator"
                  ],
                  "additionalProperties": false
                }
              },
              "target": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "package": {
                      "type": "string",
                      "minLength": 1
                    },
                    "rule": {
                      "type": "string",
                      "minLength": 1
                    },
                    "rule_hash": {
                      "type": "string",
                      "pattern": "^sha256:[0-9a-f]{64}$"
                    },
                    "anchors": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "minLength": 1
                      }
                    },
                    "shape": {
                      "type": "object",
                      "properties": {
                        "types": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "minLength": 1
                          }
                        },
                        "premises": {
                          "type": "array",
                          "items": {
                            "type": "array",
                            "prefixItems": [
                              {
                                "type": "string",
                                "minLength": 1
                              },
                              {
                                "type": "array",
                                "items": {
                                  "type": "integer",
                                  "minimum": 0
                                }
                              }
                            ],
                            "items": false,
                            "minItems": 2,
                            "maxItems": 2
                          }
                        },
                        "head": {
                          "type": "array",
                          "prefixItems": [
                            {
                              "type": "string",
                              "minLength": 1
                            },
                            {
                              "type": "array",
                              "items": {
                                "type": "integer",
                                "minimum": 0
                              }
                            }
                          ],
                          "items": false,
                          "minItems": 2,
                          "maxItems": 2
                        },
                        "premise_mode": {
                          "enum": [
                            "established",
                            "supported"
                          ],
                          "description": "Premise semantics; legacy reports without this field used established."
                        }
                      },
                      "required": [
                        "types",
                        "premises",
                        "head"
                      ],
                      "additionalProperties": false
                    },
                    "binder_map": {
                      "type": "array",
                      "items": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "description": "Target binder index to source binder index; present in current reports."
                    }
                  },
                  "required": [
                    "package",
                    "rule",
                    "rule_hash",
                    "anchors",
                    "shape"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "source",
              "target"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "source",
          "target",
          "relation",
          "direction",
          "output",
          "parameters",
          "reasons",
          "status",
          "conditions",
          "alternatives",
          "evidence"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "format",
    "profile",
    "policy",
    "policy_hash",
    "validator_hash",
    "previous_hash",
    "sources",
    "discovery",
    "decisions"
  ],
  "additionalProperties": false
}
