{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/cloud-event-types",
  "title": "CloudEventTypes",
  "description": "Per-event-type CloudEvent schemas: each $defs entry binds an envelope `type` constant to the resource schema of its `data` payload. The top-level oneOf accepts any event emitted by the reference broker.",
  "oneOf": [
    {
      "$ref": "#/$defs/PartnerRelationshipSubmitted"
    },
    {
      "$ref": "#/$defs/PartnerRelationshipAccepted"
    },
    {
      "$ref": "#/$defs/PartnerRelationshipSuspended"
    },
    {
      "$ref": "#/$defs/CapacityOfferCreated"
    },
    {
      "$ref": "#/$defs/CapacityOfferPublished"
    },
    {
      "$ref": "#/$defs/CapacityOfferWithdrawn"
    },
    {
      "$ref": "#/$defs/LoadRequestCreated"
    },
    {
      "$ref": "#/$defs/LoadRequestPublished"
    },
    {
      "$ref": "#/$defs/LoadRequestWithdrawn"
    },
    {
      "$ref": "#/$defs/MatchProposalCreated"
    },
    {
      "$ref": "#/$defs/MatchDecisionRecorded"
    },
    {
      "$ref": "#/$defs/ExecutionReferenceCreated"
    },
    {
      "$ref": "#/$defs/ExecutionOutcomeRecorded"
    },
    {
      "$ref": "#/$defs/ExecutionOutcomeCorrected"
    },
    {
      "$ref": "#/$defs/ExecutionOutcomeCancelled"
    },
    {
      "$ref": "#/$defs/ExecutionOutcomeException"
    },
    {
      "$ref": "#/$defs/TransportTenderIssued"
    },
    {
      "$ref": "#/$defs/TransportTenderCountered"
    },
    {
      "$ref": "#/$defs/TransportCommitmentFormed"
    },
    {
      "$ref": "#/$defs/ExecutionHandoverOffered"
    },
    {
      "$ref": "#/$defs/ExecutionHandoverAcknowledged"
    }
  ],
  "$defs": {
    "PartnerRelationshipSubmitted": {
      "description": "CloudEvent of type PartnerRelationshipSubmitted; `data` is a PartnerRelationship.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "PartnerRelationshipSubmitted"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/partner-relationship"
            }
          }
        }
      ]
    },
    "PartnerRelationshipAccepted": {
      "description": "CloudEvent of type PartnerRelationshipAccepted; `data` is a PartnerRelationship.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "PartnerRelationshipAccepted"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/partner-relationship"
            }
          }
        }
      ]
    },
    "PartnerRelationshipSuspended": {
      "description": "CloudEvent of type PartnerRelationshipSuspended; `data` is a PartnerRelationship.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "PartnerRelationshipSuspended"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/partner-relationship"
            }
          }
        }
      ]
    },
    "CapacityOfferCreated": {
      "description": "CloudEvent of type CapacityOfferCreated; `data` is a CapacityOffer.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "CapacityOfferCreated"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/capacity-offer"
            }
          }
        }
      ]
    },
    "CapacityOfferPublished": {
      "description": "CloudEvent of type CapacityOfferPublished; `data` is a CapacityOffer.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "CapacityOfferPublished"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/capacity-offer"
            }
          }
        }
      ]
    },
    "CapacityOfferWithdrawn": {
      "description": "CloudEvent of type CapacityOfferWithdrawn; `data` is a CapacityOffer.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "CapacityOfferWithdrawn"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/capacity-offer"
            }
          }
        }
      ]
    },
    "LoadRequestCreated": {
      "description": "CloudEvent of type LoadRequestCreated; `data` is a LoadRequest.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "LoadRequestCreated"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/load-request"
            }
          }
        }
      ]
    },
    "LoadRequestPublished": {
      "description": "CloudEvent of type LoadRequestPublished; `data` is a LoadRequest.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "LoadRequestPublished"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/load-request"
            }
          }
        }
      ]
    },
    "LoadRequestWithdrawn": {
      "description": "CloudEvent of type LoadRequestWithdrawn; `data` is a LoadRequest.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "LoadRequestWithdrawn"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/load-request"
            }
          }
        }
      ]
    },
    "MatchProposalCreated": {
      "description": "CloudEvent of type MatchProposalCreated; `data` is a MatchProposal.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "MatchProposalCreated"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/match-proposal"
            }
          }
        }
      ]
    },
    "MatchDecisionRecorded": {
      "description": "CloudEvent of type MatchDecisionRecorded; `data` is a MatchDecision.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "MatchDecisionRecorded"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/match-decision"
            }
          }
        }
      ]
    },
    "ExecutionReferenceCreated": {
      "description": "CloudEvent of type ExecutionReferenceCreated; `data` is a ExecutionReference.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionReferenceCreated"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/execution-reference"
            }
          }
        }
      ]
    },
    "ExecutionOutcomeRecorded": {
      "description": "CloudEvent of type ExecutionOutcomeRecorded; `data` is a ExecutionOutcome.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionOutcomeRecorded"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/execution-outcome"
            }
          }
        }
      ]
    },
    "ExecutionOutcomeCorrected": {
      "description": "CloudEvent of type ExecutionOutcomeCorrected; `data` is a ExecutionOutcome.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionOutcomeCorrected"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/execution-outcome"
            }
          }
        }
      ]
    },
    "ExecutionOutcomeCancelled": {
      "description": "CloudEvent of type ExecutionOutcomeCancelled; `data` is a ExecutionOutcome.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionOutcomeCancelled"
            },
            "data": {
              "allOf": [
                {
                  "$ref": "https://openfreytprotocol.example/schemas/v0/execution-outcome"
                },
                {
                  "properties": {
                    "status": {
                      "const": "cancelled"
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    "ExecutionOutcomeException": {
      "description": "CloudEvent of type ExecutionOutcomeException; `data` is a ExecutionOutcome.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionOutcomeException"
            },
            "data": {
              "allOf": [
                {
                  "$ref": "https://openfreytprotocol.example/schemas/v0/execution-outcome"
                },
                {
                  "properties": {
                    "status": {
                      "const": "exception"
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    "TransportTenderIssued": {
      "description": "CloudEvent of type TransportTenderIssued; `data` is a TransportTender.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "TransportTenderIssued"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/transport-tender"
            }
          }
        }
      ]
    },
    "TransportTenderCountered": {
      "description": "CloudEvent of type TransportTenderCountered; `data` is a TransportTender.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "TransportTenderCountered"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/transport-tender"
            }
          }
        }
      ]
    },
    "TransportCommitmentFormed": {
      "description": "CloudEvent of type TransportCommitmentFormed; `data` is a TransportCommitment.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "TransportCommitmentFormed"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/transport-commitment"
            }
          }
        }
      ]
    },
    "ExecutionHandoverOffered": {
      "description": "CloudEvent of type ExecutionHandoverOffered; `data` is an ExecutionHandover.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionHandoverOffered"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/execution-handover"
            }
          }
        }
      ]
    },
    "ExecutionHandoverAcknowledged": {
      "description": "CloudEvent of type ExecutionHandoverAcknowledged; `data` is a HandoverAcknowledgement.",
      "allOf": [
        {
          "$ref": "https://openfreytprotocol.example/schemas/v0/cloud-event-envelope"
        },
        {
          "properties": {
            "type": {
              "const": "ExecutionHandoverAcknowledged"
            },
            "data": {
              "$ref": "https://openfreytprotocol.example/schemas/v0/handover-acknowledgement"
            }
          }
        }
      ]
    }
  }
}
