{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "ProductTransition",
  "type": "object",
  "properties": {
    "profile": {
      "type": "string",
      "const": "product-lifecycle@1"
    },
    "state": {
      "type": "string",
      "const": "pendingTerminate"
    },
    "previous_state": {
      "$ref": "#/$defs/PreviousState"
    },
    "reason": {
      "anyOf": [
        {
          "$ref": "#/$defs/WithdrawalReason"
        },
        {
          "type": "null"
        }
      ]
    },
    "client_reference": {
      "type": [
        "string",
        "null"
      ]
    },
    "product": {
      "$ref": "#/$defs/SupplyProduct"
    },
    "effective": {
      "$ref": "#/$defs/EffectiveDate"
    },
    "sector": {
      "$ref": "#/$defs/SupplySector"
    },
    "extensions": {
      "$ref": "#/$defs/ProductExtensions"
    }
  },
  "additionalProperties": false,
  "required": [
    "profile",
    "state",
    "previous_state",
    "product",
    "effective",
    "sector",
    "extensions"
  ],
  "$defs": {
    "PreviousState": {
      "type": "string",
      "enum": [
        "created",
        "active",
        "pendingActive",
        "pendingTerminate"
      ]
    },
    "WithdrawalReason": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "const": "withdrawn"
        }
      },
      "required": [
        "code"
      ]
    },
    "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"
      ]
    },
    "NativeFact": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "vertrag_id": {
          "type": "string",
          "format": "uuid"
        },
        "vertrags_nr": {
          "type": "string"
        },
        "rahmenvertrag_id": {
          "type": "string",
          "format": "uuid"
        },
        "rahmenvertrag_nr": {
          "type": "string"
        },
        "lieferende": {
          "type": "string",
          "format": "date"
        },
        "grund": {
          "$ref": "#/$defs/Kuendigungsgrund"
        },
        "rechtsgrundlage": {
          "type": "string"
        },
        "kuendigungsbestaetigung": {
          "$ref": "#/$defs/Bestaetigung"
        }
      },
      "required": [
        "type",
        "vertrag_id",
        "vertrags_nr",
        "rahmenvertrag_id",
        "rahmenvertrag_nr",
        "lieferende",
        "grund",
        "rechtsgrundlage",
        "kuendigungsbestaetigung"
      ]
    },
    "Kuendigungsgrund": {
      "description": "Why a contract is being terminated. The reason, not the contract, decides\nthe notice period — a Sonderkündigung overrides whatever the contract says.",
      "oneOf": [
        {
          "description": "Ordinary termination on the contractual notice period.",
          "type": "string",
          "const": "ORDENTLICH"
        },
        {
          "description": "§ 41 Abs. 5 Satz 4 EnWG / § 5 Abs. 3 GVV — the supplier changed prices or\nterms, so the customer terminates without notice, effective the day the\nchange would take effect.",
          "type": "string",
          "const": "PREISANPASSUNG"
        },
        {
          "description": "§ 41b Abs. 5 EnWG — Haushaltskunde moving house: six weeks.",
          "type": "string",
          "const": "UMZUG"
        },
        {
          "description": "Termination declared by the new supplier on the customer's behalf in a\nLieferantenwechsel. Same period as an ordinary one; it exists as its own\nreason because § 41 Abs. 8 Nr. 3 EnWG obliges the outgoing supplier to\nreturn an electronic Kündigungsbestätigung to that supplier as well.",
          "type": "string",
          "const": "LIEFERANTENWECHSEL"
        }
      ]
    },
    "Bestaetigung": {
      "type": "object",
      "properties": {
        "erforderlich": {
          "type": "boolean"
        },
        "form": {
          "type": "string"
        },
        "rechtsgrundlage": {
          "type": "string"
        },
        "vertragsende": {
          "type": "string",
          "format": "date"
        }
      },
      "required": [
        "erforderlich",
        "form",
        "rechtsgrundlage",
        "vertragsende"
      ]
    },
    "EnergyLocation": {
      "type": "object",
      "properties": {
        "marktlokation": {
          "type": "string"
        }
      },
      "required": [
        "marktlokation"
      ]
    }
  },
  "$id": "https://hupe1980.github.io/mako/schemas/events/de.mako.vertrag.gekuendigt.json",
  "x-dataschema": "urn:open-utility-stack:product-lifecycle:1"
}
