{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "MarketRefusal",
  "anyOf": [
    {
      "$ref": "#/$defs/OrderChange"
    },
    {
      "$ref": "#/$defs/LieferbeginnAbgelehnt"
    }
  ],
  "x-dataschemas": {
    "order@1": "urn:open-utility-stack:order: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": {
      "description": "Contract, component and market response for a refused Lieferbeginn.",
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "vertrag_id": {
          "type": "string",
          "format": "uuid"
        },
        "vertrags_nr": {
          "type": "string"
        },
        "customer_id": {
          "description": "The Kunde the contract is with — the customer number of the portfolio\nroute.",
          "type": "string",
          "format": "uuid"
        },
        "erp_contract_id": {
          "description": "The caller's contract reference, where the contract was created with one.",
          "type": [
            "string",
            "null"
          ]
        },
        "bestellreferenz": {
          "description": "The front end's order reference, where the contract came from an order.",
          "type": [
            "string",
            "null"
          ]
        },
        "komp_id": {
          "type": "string",
          "format": "uuid"
        },
        "sparte": {
          "type": "string"
        },
        "malo_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "lieferbeginn": {
          "description": "The day supply begins, as the contract holds it.",
          "type": "string",
          "format": "date"
        },
        "antwortcode": {
          "description": "The grid operator's Antwortcode, where its answer carried one.",
          "type": [
            "string",
            "null"
          ]
        },
        "codeliste": {
          "description": "The Entscheidungsbaum or Codeliste that defines `antwortcode`.",
          "type": [
            "string",
            "null"
          ]
        },
        "reason": {
          "description": "The answer's text, where it carried one.",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "type",
        "vertrag_id",
        "vertrags_nr",
        "customer_id",
        "komp_id",
        "sparte",
        "lieferbeginn"
      ]
    },
    "EnergyLocation": {
      "type": "object",
      "properties": {
        "marktlokation": {
          "type": "string"
        }
      },
      "required": [
        "marktlokation"
      ]
    },
    "LieferbeginnAbgelehnt": {
      "description": "Contract, component and market response for a refused Lieferbeginn.",
      "type": "object",
      "properties": {
        "vertrag_id": {
          "type": "string",
          "format": "uuid"
        },
        "vertrags_nr": {
          "type": "string"
        },
        "customer_id": {
          "description": "The Kunde the contract is with — the customer number of the portfolio\nroute.",
          "type": "string",
          "format": "uuid"
        },
        "erp_contract_id": {
          "description": "The caller's contract reference, where the contract was created with one.",
          "type": [
            "string",
            "null"
          ]
        },
        "bestellreferenz": {
          "description": "The front end's order reference, where the contract came from an order.",
          "type": [
            "string",
            "null"
          ]
        },
        "komp_id": {
          "type": "string",
          "format": "uuid"
        },
        "sparte": {
          "type": "string"
        },
        "malo_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "lieferbeginn": {
          "description": "The day supply begins, as the contract holds it.",
          "type": "string",
          "format": "date"
        },
        "antwortcode": {
          "description": "The grid operator's Antwortcode, where its answer carried one.",
          "type": [
            "string",
            "null"
          ]
        },
        "codeliste": {
          "description": "The Entscheidungsbaum or Codeliste that defines `antwortcode`.",
          "type": [
            "string",
            "null"
          ]
        },
        "reason": {
          "description": "The answer's text, where it carried one.",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "vertrag_id",
        "vertrags_nr",
        "customer_id",
        "komp_id",
        "sparte",
        "lieferbeginn"
      ]
    }
  },
  "$id": "https://hupe1980.github.io/mako/schemas/events/de.mako.vertrag.lieferbeginn.abgelehnt.json"
}
