{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://postflight.co/aeronautiql/planning/v1/edits/transition.schema.json",
  "title": "Planning edit transition specimen v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["name", "initial", "events", "expected"],
  "properties": {
    "name": { "type": "string", "minLength": 1 },
    "requires": {
      "description": "Sibling-contract capabilities the declared outcome depends on. The runner reports PENDING instead of PASS when the sibling contract does not yet provide one.",
      "type": "array",
      "uniqueItems": true,
      "items": { "enum": ["intentDrafts"] }
    },
    "initial": { "$ref": "store.schema.json" },
    "events": {
      "type": "array",
      "items": {
        "oneOf": [
          { "$ref": "#/$defs/commandEvent" },
          { "$ref": "#/$defs/weatherEvent" },
          { "$ref": "#/$defs/mappingEvent" },
          { "$ref": "#/$defs/reloadEvent" }
        ]
      }
    },
    "expected": {
      "type": "object",
      "additionalProperties": false,
      "required": ["receipts", "document", "mappings", "weatherId", "recordCount"],
      "properties": {
        "receipts": {
          "description": "One entry per command event; null means the payload was not addressable and produced no receipt.",
          "type": "array",
          "items": { "oneOf": [{ "$ref": "receipt.schema.json" }, { "type": "null" }] }
        },
        "document": { "type": "object" },
        "mappings": { "$ref": "store.schema.json#/properties/mappings" },
        "weatherId": { "type": "string", "minLength": 1 },
        "recordCount": { "type": "integer", "minimum": 0 }
      }
    }
  },
  "$defs": {
    "commandEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "command", "recordedAt", "nextCommitId", "persistence"],
      "properties": {
        "type": { "const": "command" },
        "command": {
          "description": "Deliberately unconstrained: malformed payloads are part of the reducer contract. The runner checks that schemaInvalid matches command.schema.json."
        },
        "schemaInvalid": { "type": "boolean" },
        "recordedAt": { "$ref": "command.schema.json#/$defs/timestamp" },
        "nextCommitId": { "$ref": "command.schema.json#/$defs/id" },
        "persistence": { "enum": ["succeed", "fail"] }
      }
    },
    "weatherEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "weatherId"],
      "properties": {
        "type": { "const": "weatherUpdate" },
        "weatherId": { "type": "string", "minLength": 1 }
      }
    },
    "mappingEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "mapping"],
      "properties": {
        "type": { "const": "mappingUpdate" },
        "mapping": { "$ref": "store.schema.json#/$defs/legMapping" }
      }
    },
    "reloadEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type"],
      "properties": { "type": { "const": "reloadFromFile" } }
    }
  }
}
