import assert from 'node:assert/strict';
import { test } from 'node:test';
import { gstinCheckChar, gstinError, gstinPanMismatch, panError } from '../src/utils/taxIds.js';

test('PAN: valid, wrong shape and unknown holder type', () => {
  assert.equal(panError('AABCE1234F'), null);
  assert.match(panError('AABCE12345')!, /10 characters/);
  assert.match(panError('AABXE1234F')!, /holder type/);
});

test('GSTIN: published numbers are valid and the check digit catches typos', () => {
  assert.equal(gstinError('27AAPFU0939F1ZV'), null);
  assert.equal(gstinError('29AAGCB7383J1Z4'), null);
  assert.equal(gstinCheckChar('27AAPFU0939F1Z'), 'V');
  assert.match(gstinError('27AAPFU0939F1ZW')!, /check digit/);
});

test('GSTIN: each broken part gets its own message', () => {
  assert.match(gstinError('27AAPFU0939F1Z')!, /15 letters/);
  assert.match(gstinError('45AAPFU0939F1ZV')!, /state code/);
  assert.match(gstinError('27AAPXU0939F1ZV')!, /PAN/);
  assert.match(gstinError('27AAPFU0939F0ZV')!, /13th/);
  assert.match(gstinError('27AAPFU0939F1YV')!, /always Z/);
});

test('GSTIN and PAN must belong together', () => {
  assert.equal(gstinPanMismatch('27AABCE1234F1Z5', 'AABCE1234F'), null);
  assert.match(gstinPanMismatch('27AABCE1234F1Z5', 'AABCS5678K')!, /belongs to PAN AABCE1234F/);
});
