{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vantar.xyz/eve/spec/eve-conversation-v0.schema.json",
  "title": "Eve Conversation v0 experimental interchange",
  "description": "A global two-role conversation that can be projected into local endpoint machines.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "eve_conversation",
    "module",
    "roles",
    "types",
    "initial",
    "states"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri-reference"
    },
    "eve_conversation": {
      "const": "0.1.0"
    },
    "module": {
      "$ref": "#/$defs/module"
    },
    "roles": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": {
        "$ref": "#/$defs/role"
      }
    },
    "types": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/typeDefinition"
      }
    },
    "failures": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/failureDefinition"
      }
    },
    "initial": {
      "$ref": "#/$defs/id"
    },
    "states": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/state"
      }
    },
    "annotations": {
      "$ref": "#/$defs/annotations"
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_.-]*$"
    },
    "annotations": {
      "type": "object",
      "additionalProperties": true
    },
    "module": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "semantic_version": {
          "type": "string"
        }
      }
    },
    "role": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "placement": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "capabilities": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "typeDefinition": {
      "type": "object",
      "required": [
        "id",
        "kind"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "kind": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "failureDefinition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "description": {
          "type": "string"
        },
        "retryable": {
          "type": "boolean"
        }
      }
    },
    "onFailure": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/id"
      },
      "additionalProperties": {
        "$ref": "#/$defs/id"
      }
    },
    "state": {
      "oneOf": [
        {
          "$ref": "#/$defs/sendState"
        },
        {
          "$ref": "#/$defs/choiceState"
        },
        {
          "$ref": "#/$defs/cancelState"
        },
        {
          "$ref": "#/$defs/endState"
        },
        {
          "$ref": "#/$defs/failState"
        }
      ]
    },
    "sendState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "id",
        "from",
        "to",
        "message",
        "next"
      ],
      "properties": {
        "kind": {
          "const": "send"
        },
        "id": {
          "$ref": "#/$defs/id"
        },
        "from": {
          "$ref": "#/$defs/id"
        },
        "to": {
          "$ref": "#/$defs/id"
        },
        "message": {
          "$ref": "#/$defs/id"
        },
        "next": {
          "$ref": "#/$defs/id"
        },
        "deadline": {
          "type": "string",
          "pattern": "^[0-9]+(ns|us|ms|s|m|h)$"
        },
        "on_failure": {
          "$ref": "#/$defs/onFailure"
        }
      }
    },
    "choiceState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "id",
        "chooser",
        "branches"
      ],
      "properties": {
        "kind": {
          "const": "choice"
        },
        "id": {
          "$ref": "#/$defs/id"
        },
        "chooser": {
          "$ref": "#/$defs/id"
        },
        "branches": {
          "type": "object",
          "minProperties": 2,
          "propertyNames": {
            "$ref": "#/$defs/id"
          },
          "additionalProperties": {
            "$ref": "#/$defs/id"
          }
        },
        "on_failure": {
          "$ref": "#/$defs/onFailure"
        }
      }
    },
    "cancelState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "id",
        "from",
        "to",
        "scope",
        "next"
      ],
      "properties": {
        "kind": {
          "const": "cancel"
        },
        "id": {
          "$ref": "#/$defs/id"
        },
        "from": {
          "$ref": "#/$defs/id"
        },
        "to": {
          "$ref": "#/$defs/id"
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "next": {
          "$ref": "#/$defs/id"
        },
        "on_failure": {
          "$ref": "#/$defs/onFailure"
        }
      }
    },
    "endState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "id"
      ],
      "properties": {
        "kind": {
          "const": "end"
        },
        "id": {
          "$ref": "#/$defs/id"
        }
      }
    },
    "failState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "id",
        "failure"
      ],
      "properties": {
        "kind": {
          "const": "fail"
        },
        "id": {
          "$ref": "#/$defs/id"
        },
        "failure": {
          "$ref": "#/$defs/id"
        }
      }
    }
  }
}
