{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://b2base.eu/schemas/1.0.0-draft.1/financial/bankaccount.schema.json",
  "title": "Bankverbindungen",
  "$comment": "B2Base 1.0.0-draft.1. Projektentwurf, kein durch ISO oder andere Normungsgremien verabschiedeter Standard.",
  "type": "object",
  "description": "Bankverbindung; Unterstützung des jeweiligen Zahlungswegs muss separat geprüft werden.",
  "properties": {
    "accountHolders": {
      "type": "array",
      "description": "Verweise auf Kontoinhaber.",
      "items": {
        "$ref": "#/$defs/PartyRef"
      },
      "minItems": 1
    },
    "authorizedUsers": {
      "type": "array",
      "description": "Dokumentierte Berechtigungen; übertragen keine Zugriffsrechte.",
      "items": {
        "type": "object",
        "description": "Eine Berechtigungsangabe.",
        "properties": {
          "party": {
            "$ref": "#/$defs/PartyRef"
          },
          "authorizationLevel": {
            "type": "string",
            "minLength": 1,
            "description": "Beschriebener Umfang.",
            "enum": [
              "view",
              "transaction",
              "fullAccess"
            ]
          }
        },
        "required": [
          "party",
          "authorizationLevel"
        ],
        "additionalProperties": false
      }
    },
    "accountNumber": {
      "type": "string",
      "minLength": 1,
      "description": "Lokale Kontonummer in Originalschreibweise; kein globaler Zeichenfilter."
    },
    "iban": {
      "type": "string",
      "minLength": 1,
      "description": "IBAN ohne Leerzeichen in Großbuchstaben; zusätzlich Landeslänge und MOD-97-Prüfziffer prüfen.",
      "pattern": "^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$"
    },
    "swiftBic": {
      "type": "string",
      "minLength": 1,
      "description": "BIC in Großbuchstaben; Vergabe separat prüfen.",
      "pattern": "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$"
    },
    "routingIdentifiers": {
      "type": "array",
      "description": "Lokale Clearing-, Branch- oder Routing-Kennungen mit System.",
      "items": {
        "$ref": "#/$defs/Identifier"
      }
    },
    "bank": {
      "type": "object",
      "description": "Angaben zum kontoführenden Institut.",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Name."
        },
        "country": {
          "$ref": "#/$defs/CountryCode"
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Optionaler Institutsdatensatz.",
          "format": "uri"
        }
      },
      "required": [
        "name",
        "country"
      ],
      "additionalProperties": false
    },
    "currency": {
      "$ref": "#/$defs/CurrencyCode"
    },
    "additionalDetails": {
      "type": "string",
      "minLength": 1,
      "description": "Optionale Erläuterung."
    },
    "extensions": {
      "type": "object",
      "description": "Vereinbarte Erweiterungen; Schlüssel als absolute URI des Herausgebers. Keine stillschweigende Änderung von Kernfeldern.",
      "properties": {},
      "additionalProperties": true,
      "propertyNames": {
        "format": "uri"
      }
    }
  },
  "required": [
    "accountHolders",
    "bank",
    "currency"
  ],
  "additionalProperties": false,
  "anyOf": [
    {
      "required": [
        "iban"
      ]
    },
    {
      "required": [
        "accountNumber"
      ]
    }
  ],
  "$defs": {
    "PartyRef": {
      "type": "object",
      "description": "Verweis auf eine separat gespeicherte Person oder juristische Person; kein JSON-Schema-Verweis.",
      "properties": {
        "entityType": {
          "type": "string",
          "minLength": 1,
          "description": "Art der referenzierten Einheit.",
          "enum": [
            "person",
            "legalEntity"
          ]
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stabile absolute URI oder URN des Datensatzes, nicht dessen Name.",
          "format": "uri"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Optionale Anzeige; nicht als Identitätsschlüssel verwenden."
        }
      },
      "required": [
        "entityType",
        "id"
      ],
      "additionalProperties": false
    },
    "Identifier": {
      "type": "object",
      "description": "Kennung zusammen mit ihrem Namensraum. Führende Nullen, Trennzeichen und Groß-/Kleinschreibung erhalten.",
      "properties": {
        "value": {
          "type": "string",
          "minLength": 1,
          "description": "Kennung als Text."
        },
        "scheme": {
          "type": "string",
          "minLength": 1,
          "description": "URI des Kennungssystems; kein allgemeines weltweites Nummernformat.",
          "format": "uri"
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "description": "Optionale fachliche Bezeichnung."
        },
        "issuer": {
          "$ref": "#/$defs/Issuer"
        },
        "country": {
          "$ref": "#/$defs/CountryCode"
        },
        "validFrom": {
          "type": "string",
          "minLength": 1,
          "description": "Beginn der angegebenen Gültigkeit.",
          "format": "date"
        },
        "validUntil": {
          "type": "string",
          "minLength": 1,
          "description": "Letzter Gültigkeitstag, falls bekannt.",
          "format": "date"
        }
      },
      "required": [
        "value",
        "scheme"
      ],
      "additionalProperties": false
    },
    "Issuer": {
      "type": "object",
      "description": "Aussteller einschließlich internationaler Organisationen.",
      "properties": {
        "authority": {
          "type": "string",
          "minLength": 1,
          "description": "Originalname der Behörde oder Organisation."
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stabile Kennung des Ausstellers.",
          "format": "uri"
        },
        "country": {
          "$ref": "#/$defs/CountryCode",
          "description": "Optional: Land des Ausstellers; keine erfundene Länderkennung für internationale Organisationen."
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Optionale Verwaltungseinheit oder Zuständigkeitsbezeichnung."
        }
      },
      "required": [
        "authority"
      ],
      "additionalProperties": false
    },
    "CountryCode": {
      "type": "string",
      "minLength": 1,
      "description": "ISO 3166-1 Alpha-2, Großbuchstaben. Das Muster prüft nur die Schreibweise; zugewiesenen Code und Gültigkeitszeitpunkt gesondert prüfen.",
      "pattern": "^[A-Z]{2}$"
    },
    "CurrencyCode": {
      "type": "string",
      "minLength": 1,
      "description": "ISO-4217-Währungscode; Schreibweise allein belegt weder Zuweisung noch historische Gültigkeit.",
      "pattern": "^[A-Z]{3}$"
    }
  },
  "examples": [
    {
      "accountHolders": [
        {
          "entityType": "person",
          "id": "urn:example:person:42"
        }
      ],
      "accountNumber": "000123456789",
      "routingIdentifiers": [
        {
          "value": "021000021",
          "scheme": "https://example.org/routing/aba"
        }
      ],
      "bank": {
        "name": "Example Bank",
        "country": "US"
      },
      "currency": "USD"
    },
    {
      "accountHolders": [
        {
          "entityType": "legalEntity",
          "id": "urn:example:organisation:42"
        }
      ],
      "iban": "DE89370400440532013000",
      "bank": {
        "name": "Example Bank",
        "country": "DE"
      },
      "currency": "EUR"
    }
  ]
}
