{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/import-diff.schema.json",
  "type": "object",
  "properties": {
    "format": {
      "const": "arxo.import.diff/0.1"
    },
    "identity": {
      "type": "object",
      "properties": {
        "project": {
          "type": "string"
        },
        "language": {
          "type": "string"
        }
      },
      "required": [
        "project",
        "language"
      ],
      "additionalProperties": false
    },
    "before": {
      "type": "object",
      "properties": {
        "input_hash": {
          "type": "string"
        },
        "mapping_hash": {
          "type": "string"
        }
      },
      "required": [
        "input_hash",
        "mapping_hash"
      ],
      "additionalProperties": false
    },
    "after": {
      "type": "object",
      "properties": {
        "input_hash": {
          "type": "string"
        },
        "mapping_hash": {
          "type": "string"
        }
      },
      "required": [
        "input_hash",
        "mapping_hash"
      ],
      "additionalProperties": false
    },
    "snapshot": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Delta"
      }
    },
    "declarations": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Change"
      }
    },
    "facts": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Change"
      }
    },
    "symbols": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Change"
      }
    },
    "documents": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Change"
      }
    },
    "modules": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Change"
      }
    },
    "mapping": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Change"
      }
    },
    "rebuild": {
      "type": "object",
      "properties": {
        "basis": {
          "const": "current_import_policy_same_engine"
        },
        "before_scope": {
          "type": "string"
        },
        "after_scope": {
          "type": "string"
        },
        "global_context_changed": {
          "type": "boolean"
        },
        "records": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "basis",
        "before_scope",
        "after_scope",
        "global_context_changed",
        "records"
      ],
      "additionalProperties": false
    },
    "packages": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "status": {
              "const": "not_requested"
            }
          },
          "required": [
            "status"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "status": {
              "const": "checked"
            },
            "mode": {
              "const": "rebuild_both_with_current_generator"
            },
            "allow_partial": {
              "type": "boolean"
            },
            "diff": {
              "type": "object"
            },
            "impact": {
              "type": [
                "object",
                "null"
              ]
            },
            "members": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "properties": {
                  "kind": {
                    "enum": [
                      "added",
                      "removed",
                      "changed"
                    ]
                  },
                  "before_hash": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "after_hash": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "diff": {
                    "type": [
                      "object",
                      "null"
                    ]
                  }
                },
                "required": [
                  "kind",
                  "before_hash",
                  "after_hash",
                  "diff"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "status",
            "mode",
            "allow_partial",
            "diff",
            "impact"
          ],
          "additionalProperties": false
        }
      ]
    },
    "packaging": {
      "type": "object",
      "properties": {
        "basis": {
          "const": "current_packaging_policy_same_engine"
        },
        "before": {
          "type": "object",
          "properties": {
            "basis": {
              "enum": [
                "emitted_references/0.1",
                "single_package/0.1"
              ]
            },
            "policy_hash": {
              "type": "string"
            },
            "plan_hash": {
              "type": "string"
            }
          },
          "required": [
            "basis",
            "policy_hash",
            "plan_hash"
          ],
          "additionalProperties": false
        },
        "after": {
          "type": "object",
          "properties": {
            "basis": {
              "enum": [
                "emitted_references/0.1",
                "single_package/0.1"
              ]
            },
            "policy_hash": {
              "type": "string"
            },
            "plan_hash": {
              "type": "string"
            }
          },
          "required": [
            "basis",
            "policy_hash",
            "plan_hash"
          ],
          "additionalProperties": false
        },
        "policy": {
          "type": "object",
          "properties": {
            "packages": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/$defs/Change"
              }
            },
            "assignments": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "item": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "enum": [
                          "type",
                          "predicate",
                          "reification",
                          "declaration",
                          "fact"
                        ]
                      },
                      "source": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "kind",
                      "source"
                    ],
                    "additionalProperties": false
                  },
                  "before": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "after": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "item",
                  "before",
                  "after"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "packages",
            "assignments"
          ],
          "additionalProperties": false
        },
        "packages": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/Change"
          }
        },
        "existing": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/Change"
          }
        },
        "ownership": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "item": {
                "type": "object",
                "properties": {
                  "kind": {
                    "enum": [
                      "type",
                      "predicate",
                      "reification",
                      "declaration",
                      "fact"
                    ]
                  },
                  "source": {
                    "type": "string"
                  }
                },
                "required": [
                  "kind",
                  "source"
                ],
                "additionalProperties": false
              },
              "before": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "package": {
                        "type": "string"
                      },
                      "namespace": {
                        "type": "string"
                      },
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "package",
                      "namespace",
                      "name"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "after": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "package": {
                        "type": "string"
                      },
                      "namespace": {
                        "type": "string"
                      },
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "package",
                      "namespace",
                      "name"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "item",
              "before",
              "after"
            ],
            "additionalProperties": false
          }
        },
        "references": {
          "type": "object",
          "properties": {
            "added": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "from": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "enum": [
                          "type",
                          "predicate",
                          "reification",
                          "declaration",
                          "fact"
                        ]
                      },
                      "source": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "kind",
                      "source"
                    ],
                    "additionalProperties": false
                  },
                  "to": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "enum": [
                          "type",
                          "predicate",
                          "reification",
                          "declaration",
                          "fact"
                        ]
                      },
                      "source": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "kind",
                      "source"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "from",
                  "to"
                ],
                "additionalProperties": false
              }
            },
            "removed": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "from": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "enum": [
                          "type",
                          "predicate",
                          "reification",
                          "declaration",
                          "fact"
                        ]
                      },
                      "source": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "kind",
                      "source"
                    ],
                    "additionalProperties": false
                  },
                  "to": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "enum": [
                          "type",
                          "predicate",
                          "reification",
                          "declaration",
                          "fact"
                        ]
                      },
                      "source": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "kind",
                      "source"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "from",
                  "to"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "added",
            "removed"
          ],
          "additionalProperties": false
        },
        "scheduling": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/Delta"
          }
        }
      },
      "required": [
        "basis",
        "before",
        "after",
        "policy",
        "packages",
        "existing",
        "ownership",
        "references",
        "scheduling"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "format",
    "identity",
    "before",
    "after",
    "snapshot",
    "declarations",
    "facts",
    "symbols",
    "documents",
    "modules",
    "mapping",
    "rebuild"
  ],
  "additionalProperties": false,
  "$defs": {
    "Delta": {
      "type": "object",
      "properties": {
        "before": {},
        "after": {}
      },
      "required": [
        "before",
        "after"
      ],
      "additionalProperties": false
    },
    "Change": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "added",
            "removed",
            "changed"
          ]
        },
        "fields": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/Delta"
          }
        }
      },
      "required": [
        "kind",
        "fields"
      ],
      "additionalProperties": false
    }
  }
}
