import { describe, it, expect } from 'vitest';
import { isValidVietnamPhone, normalizeVietnamPhone } from '../vietnam-phone.validator';

describe('isValidVietnamPhone', () => {
  it.each([
    '0912345678',
    '0351234567',
    '0561234567',
    '0701234567',
    '0812345678',
    '+84912345678',
    '84912345678',
  ])('should accept valid phone: %s', (phone) => {
    expect(isValidVietnamPhone(phone)).toBe(true);
  });

  it.each([
    '012345678',
    '091234567', // too short
    '09123456789', // too long
    '1234567890',
    '+1234567890',
    '',
  ])('should reject invalid phone: %s', (phone) => {
    expect(isValidVietnamPhone(phone)).toBe(false);
  });
});

describe('normalizeVietnamPhone', () => {
  it('should normalize 0-prefix to +84', () => {
    expect(normalizeVietnamPhone('0912345678')).toBe('+84912345678');
  });

  it('should normalize 84-prefix to +84', () => {
    expect(normalizeVietnamPhone('84912345678')).toBe('+84912345678');
  });

  it('should keep +84 prefix', () => {
    expect(normalizeVietnamPhone('+84912345678')).toBe('+84912345678');
  });

  it('should return null for invalid phone', () => {
    expect(normalizeVietnamPhone('invalid')).toBeNull();
  });
});
