{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "bank_data.schema.json",
  "title": "bank_data",
  "description": "Enthält Konto-/SEPA- Daten des Versicherungsnehmers",
  "type": "object",
  "properties": {
    "iban": {
      "type": "string",
      "minLength": 1,
      "pattern": "^DE\\d{20}$",
      "description": "IBAN"
    },
    "sepa_by_check24": {
      "type": "boolean",
      "description": "Ob SEPA-Informationen durch CHECK24 beschafft werden"
    },
    "owner_differs": {
      "type": "boolean",
      "description": "Ob Kontoinhaber abweichend zu Versicherungsnehmer ist"
    },
    "owner_address_differs": {
      "type": "boolean",
      "description": "Ob Adresse abweichend zu der des VN ist"
    }
  },

  "required": ["iban", "sepa_by_check24", "owner_differs", "owner_address_differs"],

  "$defs" : {
  "def_owner": {
    "type": "object",
      "properties" : {
      "firstname": {
        "type": "string",
        "minLength": 1,
        "description": "Vorname des Kontoinhabers"
      },
      "lastname": {
        "type": "string",
        "minLength": 1,
        "description": "Nachname des Kontoinhabers"
      }
    },
    "required": ["firstname", "lastname"]
  },
  "def_sepa": {
    "description": "SEPA-Informationen",
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "SEPA-Text",
        "minLength": 1
      },
      "bankname": {
        "type": "string",
        "description": "Bankname",
        "minLength": 1
      },
      "iban_anonymized": {
        "type": "string",
        "minLength": 1,
        "description": "Anonymisierte IBAN"
      },
      "accountowner_name": {
        "type": "string",
        "minLength": 1,
        "description": "Name des Kontoinhabers"
      },
      "accountowner_address": {
        "type": "string",
        "minLength": 1,
        "description": "Adresse des Kontoinhabers"
      },
      "comment": {
        "type": "string",
        "description": "Bemerkung bzgl. des VN/des Kontos"
      },
      "date": {
        "type": "string",
        "minLength": 1,
        "pattern": "(\\d{4}|\\d{2})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})",
        "description": "Datum der Zustimmung des Kunden"
      }
    },
    "required": ["text", "bankname", "iban_anonymized", "accountowner_name", "accountowner_address", "date"]
  }
},

  "allOf": [
    {
      "if": {"properties": {"owner_differs": {"const": true}}},
      "then": {
        "properties": {"owner": {"$ref": "#/$defs/def_owner"}},
        "required": ["owner"]
      }
    },
    {
      "if": {"properties": {"owner_address_differs": {"const": true}}},
      "then": {
        "properties": {"owner_address": {"$ref": "adress.schema.json"}},
        "required": ["owner_address"]}
    },
    {
      "if": {"properties": {"sepa_by_check24": {"const": true}}},
      "then": {
        "properties": {"sepa": {"$ref": "#/$defs/def_sepa"}},
        "required": ["sepa"]}
    }
  ]
}
