{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.sap.com/schemas/sap/business-partner.json",
  "title": "SAP Business Partner",
  "description": "Schema for SAP business partner master data used across S/4HANA, Business One, and SuccessFactors APIs.",
  "type": "object",
  "required": ["BusinessPartner", "BusinessPartnerCategory"],
  "properties": {
    "BusinessPartner": {
      "type": "string",
      "description": "Unique business partner number",
      "maxLength": 10,
      "pattern": "^[0-9A-Z]+$"
    },
    "BusinessPartnerCategory": {
      "type": "string",
      "description": "Category of the business partner: 1=Organization, 2=Person, 3=Group",
      "enum": ["1", "2", "3"]
    },
    "BusinessPartnerFullName": {
      "type": "string",
      "description": "Full name of the business partner",
      "maxLength": 81
    },
    "BusinessPartnerGrouping": {
      "type": "string",
      "description": "Business partner grouping for number range assignment",
      "maxLength": 4
    },
    "FirstName": {
      "type": "string",
      "description": "First name for person-type business partners",
      "maxLength": 40
    },
    "LastName": {
      "type": "string",
      "description": "Last name for person-type business partners",
      "maxLength": 40
    },
    "OrganizationBPName1": {
      "type": "string",
      "description": "Organization name (line 1) for organization-type business partners",
      "maxLength": 40
    },
    "OrganizationBPName2": {
      "type": "string",
      "description": "Organization name (line 2)",
      "maxLength": 40
    },
    "SearchTerm1": {
      "type": "string",
      "description": "Primary search term",
      "maxLength": 20
    },
    "Language": {
      "type": "string",
      "description": "Correspondence language (ISO 639-1)",
      "maxLength": 2,
      "pattern": "^[A-Z]{2}$"
    },
    "Industry": {
      "type": "string",
      "description": "Industry sector key",
      "maxLength": 10
    },
    "LegalForm": {
      "type": "string",
      "description": "Legal form of the organization",
      "maxLength": 2
    },
    "CreationDate": {
      "type": "string",
      "format": "date",
      "description": "Date the business partner record was created"
    },
    "LastChangeDate": {
      "type": "string",
      "format": "date",
      "description": "Date of last modification"
    },
    "IsNaturalPerson": {
      "type": "string",
      "description": "Whether the business partner is a natural person",
      "enum": ["X", ""]
    },
    "Addresses": {
      "type": "array",
      "description": "Business partner addresses",
      "items": {
        "$ref": "#/$defs/Address"
      }
    },
    "BankAccounts": {
      "type": "array",
      "description": "Business partner bank account details",
      "items": {
        "$ref": "#/$defs/BankAccount"
      }
    },
    "TaxNumbers": {
      "type": "array",
      "description": "Tax identification numbers",
      "items": {
        "$ref": "#/$defs/TaxNumber"
      }
    },
    "Roles": {
      "type": "array",
      "description": "Business partner roles (customer, supplier, etc.)",
      "items": {
        "$ref": "#/$defs/Role"
      }
    }
  },
  "$defs": {
    "Address": {
      "type": "object",
      "description": "Business partner address record",
      "properties": {
        "AddressID": {
          "type": "string",
          "description": "Address identifier"
        },
        "Country": {
          "type": "string",
          "description": "Country code (ISO 3166-1 alpha-2)",
          "maxLength": 2,
          "pattern": "^[A-Z]{2}$"
        },
        "Region": {
          "type": "string",
          "description": "Region or state code",
          "maxLength": 3
        },
        "CityName": {
          "type": "string",
          "description": "City name",
          "maxLength": 40
        },
        "PostalCode": {
          "type": "string",
          "description": "Postal code",
          "maxLength": 10
        },
        "StreetName": {
          "type": "string",
          "description": "Street name",
          "maxLength": 60
        },
        "HouseNumber": {
          "type": "string",
          "description": "House number",
          "maxLength": 10
        }
      }
    },
    "BankAccount": {
      "type": "object",
      "description": "Business partner bank account details",
      "properties": {
        "BankCountryKey": {
          "type": "string",
          "description": "Country key of the bank",
          "maxLength": 2
        },
        "BankNumber": {
          "type": "string",
          "description": "Bank routing or sort code",
          "maxLength": 15
        },
        "BankAccount": {
          "type": "string",
          "description": "Bank account number",
          "maxLength": 18
        },
        "IBAN": {
          "type": "string",
          "description": "International Bank Account Number",
          "maxLength": 34,
          "pattern": "^[A-Z]{2}[0-9]{2}[A-Z0-9]+$"
        },
        "SWIFTCode": {
          "type": "string",
          "description": "SWIFT/BIC code",
          "maxLength": 11
        }
      }
    },
    "TaxNumber": {
      "type": "object",
      "description": "Tax identification number",
      "properties": {
        "BPTaxType": {
          "type": "string",
          "description": "Tax number category"
        },
        "BPTaxNumber": {
          "type": "string",
          "description": "Tax identification number value"
        }
      }
    },
    "Role": {
      "type": "object",
      "description": "Business partner role assignment",
      "properties": {
        "BusinessPartnerRole": {
          "type": "string",
          "description": "Role code (e.g., FLCU01=Customer, FLVN01=Vendor)"
        }
      }
    }
  }
}
