{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "EmergencySupplyStarted",
  "description": "Ersatzversorgung starts on the component's Lieferbeginn without a checkout order.",
  "type": "object",
  "properties": {
    "profile": {
      "type": "string",
      "const": "product-lifecycle@1"
    },
    "state": {
      "type": "string",
      "const": "active"
    },
    "previous_state": {
      "type": "string",
      "const": "created"
    },
    "product": {
      "$ref": "#/$defs/SupplyProduct"
    },
    "effective": {
      "$ref": "#/$defs/EffectiveDate"
    },
    "sector": {
      "$ref": "#/$defs/SupplySector"
    },
    "reason": {
      "$ref": "#/$defs/EmergencyReason"
    },
    "extensions": {
      "$ref": "#/$defs/ProductExtensions"
    }
  },
  "additionalProperties": false,
  "required": [
    "profile",
    "state",
    "previous_state",
    "product",
    "effective",
    "sector",
    "reason",
    "extensions"
  ],
  "$defs": {
    "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"
      ]
    },
    "EmergencyReason": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "const": "ersatzversorgung"
        }
      },
      "required": [
        "code"
      ]
    },
    "ProductExtensions": {
      "type": "object",
      "properties": {
        "de.mako": {
          "$ref": "#/$defs/NativeFact"
        },
        "energy": {
          "anyOf": [
            {
              "$ref": "#/$defs/EnergyLocation"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "de.mako"
      ]
    },
    "NativeFact": {
      "description": "Contract and market details of an Ersatzversorgung start.",
      "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"
        },
        "ende": {
          "description": "The day the Ersatzversorgung ends at the latest: „spätestens aber drei\nMonate nach Beginn\" (§ 38 Abs. 4 Satz 1 EnWG).",
          "type": "string",
          "format": "date"
        },
        "kunde_name": {
          "description": "The household's name as the Netzbetreiber stated it (`NAD+Z67`, Kann)\nor as the contract's Kunde holds it; absent where neither names one.",
          "type": [
            "string",
            "null"
          ]
        },
        "quelle": {
          "description": "`55013` when the Netzbetreiber's Zuordnung opened it, `api` when it\nwas created through the contract route.",
          "type": "string"
        }
      },
      "required": [
        "type",
        "vertrag_id",
        "vertrags_nr",
        "customer_id",
        "komp_id",
        "sparte",
        "lieferbeginn",
        "ende",
        "quelle"
      ]
    },
    "EnergyLocation": {
      "type": "object",
      "properties": {
        "marktlokation": {
          "type": "string"
        }
      },
      "required": [
        "marktlokation"
      ]
    }
  },
  "$id": "https://hupe1980.github.io/mako/schemas/events/de.mako.vertrag.ersatzversorgung.begonnen.json",
  "x-dataschema": "urn:open-utility-stack:product-lifecycle:1"
}
