{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Acceptance",
  "anyOf": [
    {
      "$ref": "#/$defs/OrderChange"
    },
    {
      "$ref": "#/$defs/SupplyCreated"
    }
  ],
  "x-dataschemas": {
    "order@1": "urn:open-utility-stack:order:1",
    "product-lifecycle@1": "urn:open-utility-stack:product-lifecycle:1"
  },
  "$defs": {
    "OrderChange": {
      "type": "object",
      "properties": {
        "profile": {
          "type": "string",
          "const": "order@1"
        },
        "client_reference": {
          "type": "string"
        },
        "order": {
          "$ref": "#/$defs/OrderId"
        },
        "state": {
          "$ref": "#/$defs/OrderState"
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/OrderItem"
          }
        },
        "reason": {
          "anyOf": [
            {
              "$ref": "#/$defs/OrderReason"
            },
            {
              "type": "null"
            }
          ]
        },
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "extensions": {
          "$ref": "#/$defs/OrderExtensions"
        }
      },
      "additionalProperties": false,
      "required": [
        "profile",
        "client_reference",
        "order",
        "state",
        "items",
        "at",
        "extensions"
      ]
    },
    "OrderId": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        }
      },
      "required": [
        "id"
      ]
    },
    "OrderState": {
      "type": "string",
      "enum": [
        "acknowledged",
        "rejected",
        "inProgress",
        "completed",
        "partial",
        "failed",
        "cancelled"
      ]
    },
    "OrderItem": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "action": {
          "type": "string",
          "const": "add"
        },
        "product": {
          "anyOf": [
            {
              "$ref": "#/$defs/OrderId"
            },
            {
              "type": "null"
            }
          ]
        },
        "state": {
          "$ref": "#/$defs/OrderState"
        }
      },
      "required": [
        "id",
        "action",
        "state"
      ]
    },
    "OrderReason": {
      "type": "object",
      "properties": {
        "code": {
          "$ref": "#/$defs/ReasonCode"
        }
      },
      "required": [
        "code"
      ]
    },
    "ReasonCode": {
      "type": "string",
      "enum": [
        "order.refused",
        "market.rejected",
        "other",
        "withdrawn"
      ]
    },
    "OrderExtensions": {
      "type": "object",
      "properties": {
        "de.mako": {
          "$ref": "#/$defs/NativeFact"
        },
        "energy": {
          "anyOf": [
            {
              "$ref": "#/$defs/EnergyLocation"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "de.mako"
      ]
    },
    "NativeFact": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "bestellung_id": {
          "type": "string",
          "format": "uuid"
        },
        "bestellreferenz": {
          "type": "string"
        },
        "vertrag_id": {
          "type": "string",
          "format": "uuid"
        },
        "customer_id": {
          "type": "string",
          "format": "uuid"
        },
        "vertrags_nr": {
          "type": "string"
        },
        "vertragsschluss_am": {
          "type": "string",
          "format": "date-time"
        },
        "widerrufsfrist": {
          "anyOf": [
            {
              "$ref": "#/$defs/Widerrufsfrist"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "type",
        "bestellung_id",
        "bestellreferenz",
        "vertrag_id",
        "customer_id",
        "vertrags_nr",
        "vertragsschluss_am"
      ]
    },
    "Widerrufsfrist": {
      "type": "object",
      "properties": {
        "beginn": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "ende": {
          "type": "string",
          "format": "date"
        },
        "erloeschen": {
          "type": "string",
          "format": "date"
        }
      },
      "required": [
        "ende",
        "erloeschen"
      ]
    },
    "EnergyLocation": {
      "type": "object",
      "properties": {
        "marktlokation": {
          "type": "string"
        }
      },
      "required": [
        "marktlokation"
      ]
    },
    "SupplyCreated": {
      "description": "A supply contract on its creation date.",
      "type": "object",
      "properties": {
        "client_reference": {
          "type": [
            "string",
            "null"
          ]
        },
        "profile": {
          "type": "string",
          "const": "product-lifecycle@1"
        },
        "state": {
          "type": "string",
          "const": "created"
        },
        "product": {
          "$ref": "#/$defs/SupplyProduct"
        },
        "effective": {
          "$ref": "#/$defs/EffectiveDate"
        },
        "sector": {
          "$ref": "#/$defs/SupplySector"
        },
        "extensions": {
          "$ref": "#/$defs/ProductExtensions"
        }
      },
      "additionalProperties": false,
      "required": [
        "profile",
        "state",
        "product",
        "effective",
        "sector",
        "extensions"
      ]
    },
    "SupplyProduct": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "number": {
          "type": "string",
          "maxLength": 64,
          "pattern": "\\S"
        }
      },
      "additionalProperties": false,
      "required": [
        "id",
        "number"
      ]
    },
    "EffectiveDate": {
      "type": "object",
      "properties": {
        "date": {
          "type": "string",
          "format": "date"
        },
        "zone": {
          "type": "string",
          "const": "Europe/Berlin"
        }
      },
      "additionalProperties": false,
      "required": [
        "date",
        "zone"
      ]
    },
    "SupplySector": {
      "type": "string",
      "enum": [
        "electricity",
        "gas",
        "heat",
        "water",
        "charging",
        "other"
      ]
    },
    "ProductExtensions": {
      "type": "object",
      "properties": {
        "de.mako": {
          "$ref": "#/$defs/NativeFact"
        },
        "energy": {
          "anyOf": [
            {
              "$ref": "#/$defs/EnergyLocation"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "de.mako"
      ]
    }
  },
  "$id": "https://hupe1980.github.io/mako/schemas/events/de.mako.vertrag.bestellung.angenommen.json"
}
