{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:open-utility-stack:erasure:1",
  "title": "erasure@1",
  "description": "A person's data was erased by the emitter, and every consumer that received data about them must erase or anonymise its copies (G7; Art. 17(2) and Art. 19 GDPR). The event names the person only by references consumers already hold. Each consumer keeps what its own law requires it to keep and says so in its confirmation (`#/$defs/Confirmation`). Erasure is not crypto-shredding: a destroyed key is defence in depth, not proof.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "profile",
    "subject",
    "basis",
    "erased_at"
  ],
  "properties": {
    "profile": {
      "const": "erasure@1"
    },
    "client_reference": {
      "description": "The data subject's request, where one caused the erasure, so the request's handling can be traced.",
      "$ref": "urn:open-utility-stack:common:reference:1#/$defs/ClientReference"
    },
    "subject": {
      "description": "The reference consumers know the person by.",
      "allOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "id"
          ],
          "properties": {
            "kind": {
              "$ref": "#/$defs/Kind"
            },
            "id": {
              "description": "The emitter's reference, as consumers received it; never a name.",
              "type": "string",
              "pattern": "\\S",
              "maxLength": 160
            },
            "scheme": {
              "description": "Whose id it is, where several systems' ids are listed: `esales`, `konto`, `mako`.",
              "type": "string",
              "pattern": "^[a-z][a-z0-9-]*$",
              "maxLength": 32
            }
          }
        }
      ]
    },
    "also_known_as": {
      "description": "Other references the emitter knows for the same person, so a consumer that filed them under another id finds them.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "id"
        ],
        "properties": {
          "kind": {
            "$ref": "#/$defs/Kind"
          },
          "id": {
            "description": "The emitter's reference, as consumers received it; never a name.",
            "type": "string",
            "pattern": "\\S",
            "maxLength": 160
          },
          "scheme": {
            "description": "Whose id it is, where several systems' ids are listed: `esales`, `konto`, `mako`.",
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*$",
            "maxLength": 32
          }
        }
      }
    },
    "basis": {
      "description": "Why: the person's request (Art. 17(1)(a) GDPR), the end of a retention period, a withdrawn consent, a court order.",
      "enum": [
        "request",
        "retention-ended",
        "consent-withdrawn",
        "objection",
        "order",
        "other"
      ]
    },
    "erased_at": {
      "$ref": "urn:open-utility-stack:common:time:1#/$defs/Instant"
    },
    "retained": {
      "description": "What the emitter itself keeps, and until when; information for consumers, not an instruction to them.",
      "allOf": [
        {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "category",
              "basis",
              "until"
            ],
            "properties": {
              "category": {
                "description": "What is kept: invoices, contract evidence, market messages.",
                "type": "string",
                "pattern": "\\S",
                "maxLength": 80
              },
              "basis": {
                "description": "The norm that requires keeping it (Art. 17(3)(b) GDPR with § 147 AO, § 257 HGB).",
                "type": "string",
                "pattern": "\\S",
                "maxLength": 120
              },
              "until": {
                "$ref": "urn:open-utility-stack:common:time:1#/$defs/Date"
              }
            }
          }
        }
      ]
    },
    "confirm_to": {
      "description": "Informational: where the emitter collects confirmations. A consumer delivers its confirmation only over the subscriptions its operator configured, never to a URL taken from the event (that would let any sender point it at an arbitrary host); it may use the value to select among configured endpoints.",
      "type": "string",
      "format": "uri"
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$"
      },
      "additionalProperties": {
        "type": "object"
      }
    }
  },
  "$defs": {
    "Confirmation": {
      "description": "A consumer's answer: what it did with its copies, or that it will finish by a date (`pending`). Validate against `urn:open-utility-stack:erasure:1#/$defs/Confirmation`.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile",
        "subject",
        "consumer",
        "done_at",
        "outcome"
      ],
      "properties": {
        "profile": {
          "const": "erasure@1"
        },
        "subject": {
          "allOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "id"
              ],
              "properties": {
                "kind": {
                  "$ref": "#/$defs/Kind"
                },
                "id": {
                  "description": "The emitter's reference, as consumers received it; never a name.",
                  "type": "string",
                  "pattern": "\\S",
                  "maxLength": 160
                },
                "scheme": {
                  "description": "Whose id it is, where several systems' ids are listed: `esales`, `konto`, `mako`.",
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9-]*$",
                  "maxLength": 32
                }
              }
            }
          ]
        },
        "erasure": {
          "description": "The CloudEvent `id` of the erasure event confirmed. An emitter without its own bus uses its record id of the erasure as that `id`, and its relay keeps it.",
          "type": "string",
          "pattern": "\\S",
          "maxLength": 256
        },
        "consumer": {
          "description": "The confirming system, by role or domain.",
          "type": "string",
          "pattern": "\\S",
          "maxLength": 128
        },
        "done_at": {
          "$ref": "urn:open-utility-stack:common:time:1#/$defs/Instant"
        },
        "outcome": {
          "description": "`erased`: nothing left; `anonymised`: data kept without any link to the person; `none-held`: the consumer had nothing; `retained`: kept for the listed reasons only; `pending`: received; no new use of the person's data starts, what still runs ends with the action an operator must take (removing a row from a reviewed file or an export), and the final answer follows by `expected_by`. Use a norm requires is `retained`, not `pending`. A `pending` answer is followed by a final one for the same `erasure`.",
          "enum": [
            "erased",
            "anonymised",
            "none-held",
            "retained",
            "pending"
          ]
        },
        "retained": {
          "allOf": [
            {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "category",
                  "basis",
                  "until"
                ],
                "properties": {
                  "category": {
                    "description": "What is kept: invoices, contract evidence, market messages.",
                    "type": "string",
                    "pattern": "\\S",
                    "maxLength": 80
                  },
                  "basis": {
                    "description": "The norm that requires keeping it (Art. 17(3)(b) GDPR with § 147 AO, § 257 HGB).",
                    "type": "string",
                    "pattern": "\\S",
                    "maxLength": 120
                  },
                  "until": {
                    "$ref": "urn:open-utility-stack:common:time:1#/$defs/Date"
                  }
                }
              }
            }
          ]
        },
        "expected_by": {
          "description": "With `pending` only: the date by which the final answer follows.",
          "$ref": "urn:open-utility-stack:common:time:1#/$defs/Date"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "outcome": {
                "const": "retained"
              }
            }
          },
          "then": {
            "required": [
              "retained"
            ]
          },
          "else": {
            "not": {
              "required": [
                "retained"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "outcome": {
                "const": "pending"
              }
            },
            "required": [
              "outcome"
            ]
          },
          "then": {
            "required": [
              "expected_by"
            ]
          },
          "else": {
            "not": {
              "required": [
                "expected_by"
              ]
            }
          }
        }
      ]
    },
    "Kind": {
      "description": "What the reference names: a party (person or company), a contract account, a contract, a lead, a supply point's occupancy, a job, a metering point (Marktlokation or Messlokation), a controllable unit (an EMS target or a market resource such as a Redispatch TR-ID), a device (a smart meter gateway, a meter serial, a controllable device's identifier).",
      "enum": [
        "party",
        "account",
        "contract",
        "lead",
        "occupancy",
        "job",
        "metering-point",
        "unit",
        "device",
        "other"
      ]
    }
  }
}
