{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jig-harness.dev/protocol/forge-claims/v1/schemas/dispatch-launch-claim.json",
  "allOf": [
    {
      "type": "object",
      "properties": {
        "kind": {
          "const": "dispatch-launch-claim"
        },
        "v": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1
        },
        "key": {
          "type": "string",
          "pattern": "^drive$"
        },
        "writer": {
          "type": "object",
          "properties": {
            "login": {
              "type": "string",
              "minLength": 1
            },
            "host": {
              "type": "string",
              "minLength": 1
            },
            "bootId": {
              "type": "string"
            },
            "pid": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "start": {
              "type": "string"
            }
          },
          "required": ["host"],
          "additionalProperties": true
        },
        "at": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$"
        },
        "generation": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": ["kind", "v", "key", "writer", "at"],
      "additionalProperties": true
    },
    {
      "allOf": [
        {
          "type": "object",
          "properties": {
            "generation": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "pr": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            }
          },
          "required": ["generation", "pr"],
          "additionalProperties": true
        },
        {
          "type": "object",
          "properties": {
            "action": {
              "enum": ["rearm", "takeover"]
            },
            "record": {
              "type": "string",
              "pattern": "^\\d{8}T\\d{6}Z-[a-f\\d]{8}$"
            },
            "host": {
              "type": "string",
              "minLength": 1
            },
            "facts": {
              "type": "string"
            },
            "change": {
              "type": "string"
            },
            "earlier": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "owner": {
              "type": "boolean"
            },
            "conflictStop": true,
            "end": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "state": {
                      "const": "ended"
                    },
                    "at": {
                      "type": "string"
                    },
                    "exit": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "outcome": {
                      "anyOf": [
                        {
                          "enum": ["done", "failed"]
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "by": true,
                    "cause": true
                  },
                  "required": ["state", "at", "exit"],
                  "additionalProperties": true
                },
                {
                  "type": "object",
                  "properties": {
                    "state": {
                      "const": "died"
                    },
                    "at": {
                      "type": "string"
                    },
                    "reason": {
                      "type": "string"
                    },
                    "executed": {
                      "const": false
                    }
                  },
                  "required": ["state", "at", "reason"],
                  "additionalProperties": true
                }
              ]
            }
          },
          "required": ["action", "record", "host", "facts"],
          "additionalProperties": true
        }
      ]
    }
  ]
}
