{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:open-utility-stack:bill-section:1",
  "title": "bill-section@1",
  "description": "What a contract engine contributes to a convergent bill: its section's heading and the texts and facts its sector's law requires on every bill (§ 40 EnWG for electricity and gas, § 62 TKG and the TK-Transparenzverordnung for telecoms, AVBWasserV, AVBFernwärmeV and FFVAV for water and heat). The account system (konto) places the section and never edits it; it knows no sector law (D-015, G9).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "profile",
    "key",
    "producer",
    "contract",
    "title",
    "legal_basis",
    "blocks"
  ],
  "properties": {
    "profile": {
      "const": "bill-section@1"
    },
    "key": {
      "description": "The section key the producer's rated charges name in `section`. Unique per account and bill: a producer with two contracts on one account (a household and a heat-pump tariff) gives each its own key.",
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]*$",
      "maxLength": 32
    },
    "producer": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]*$",
      "maxLength": 32
    },
    "contract": {
      "description": "The contract the section is for, as `<producer>:<kind>/<id>`.",
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*/\\S+$",
      "maxLength": 160
    },
    "period": {
      "description": "The dates the section covers, both inclusive.",
      "$ref": "urn:open-utility-stack:common:time:1#/$defs/DatePeriod"
    },
    "ordinal": {
      "description": "The producer's preferred position; the account system decides, ties break by key.",
      "type": "integer",
      "minimum": 1,
      "maximum": 99
    },
    "title": {
      "description": "The heading the customer reads: Strom, Glasfaser, Trinkwasser.",
      "type": "string",
      "pattern": "\\S",
      "maxLength": 80
    },
    "legal_basis": {
      "description": "The norms whose mandatory content the section carries.",
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "pattern": "\\S",
        "maxLength": 80
      }
    },
    "facts": {
      "description": "Mandatory figures, in the order they are shown: a meter number, readings, the consumption of the same period last year, a CO₂ share.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "label",
          "value"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*$",
            "maxLength": 40
          },
          "label": {
            "type": "string",
            "pattern": "\\S",
            "maxLength": 80
          },
          "value": {
            "description": "As shown, already formatted by the producer: `312,4 kWh`, `1 234 567`.",
            "type": "string",
            "pattern": "\\S",
            "maxLength": 200
          },
          "basis": {
            "description": "The norm that requires this fact, if one does.",
            "type": "string",
            "maxLength": 80
          }
        }
      }
    },
    "blocks": {
      "description": "Mandatory texts by id: the supply point, the dispute-resolution body, the right to switch, a price-change notice.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "text"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*$",
            "maxLength": 40
          },
          "text": {
            "type": "string",
            "pattern": "\\S",
            "maxLength": 4000
          },
          "basis": {
            "type": "string",
            "maxLength": 80
          }
        }
      }
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$"
      },
      "additionalProperties": {
        "type": "object"
      }
    }
  }
}
