import assert from 'node:assert/strict';
import test from 'node:test';
import { duplicateIdentityField, phoneKey } from './person-identity';

test('normalizes Indian phone formatting and country code', () => {
  assert.equal(phoneKey('+91 98765-43210'), '9876543210');
  assert.equal(duplicateIdentityField({ phone: '+91 98765 43210' }, { phone: '9876543210' }), 'phone');
});

test('matches email and ID case-insensitively', () => {
  assert.equal(duplicateIdentityField({ email: 'Guest@Example.com' }, { email: 'guest@example.com' }), 'email');
  assert.equal(duplicateIdentityField({ kycIdNumber: 'AB 12 34' }, { kycIdNumber: 'ab1234' }), 'ID number');
});

test('does not treat a shared name or missing identifiers as a duplicate', () => {
  assert.equal(duplicateIdentityField({}, {}), null);
});
