const BANK_ACCOUNT_WEIGHTS = [
  3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7,
];

export function validateBankAccountNumber(value: string): boolean {
  if (!/^\d{18}$/.test(value)) return false;

  const digits = value.split('').map(Number);
  const sum = BANK_ACCOUNT_WEIGHTS.reduce(
    (acc, weight, i) => acc + ((digits[i] * weight) % 10),
    0,
  );
  const expectedCheckDigit = (10 - (sum % 10)) % 10;

  return digits[17] === expectedCheckDigit;
}
