import assert from 'node:assert/strict';
import test from 'node:test';
import {
  formatDocumentSequencePeriod,
  normalizeDocumentSequenceProductType,
  resolveDocumentSequenceOrganizationCode,
  resolveDocumentSequenceProductTypeCode
} from './config';

test('resolveDocumentSequenceProductTypeCode supports current CRM product type aliases', () => {
  assert.equal(resolveDocumentSequenceProductTypeCode('crane'), 'CR');
  assert.equal(resolveDocumentSequenceProductTypeCode('dockdoor'), 'DK');
  assert.equal(resolveDocumentSequenceProductTypeCode('dock_door'), 'DK');
  assert.equal(resolveDocumentSequenceProductTypeCode('solarcell'), 'SC');
  assert.equal(resolveDocumentSequenceProductTypeCode('service'), 'SV');
  assert.equal(resolveDocumentSequenceProductTypeCode('sparepart'), 'SP');
});

test('resolveDocumentSequenceOrganizationCode uses centralized slug mapping', () => {
  assert.equal(resolveDocumentSequenceOrganizationCode('alla'), 'A');
  assert.equal(resolveDocumentSequenceOrganizationCode('alla-demo'), 'A');
  assert.equal(resolveDocumentSequenceOrganizationCode('onvalla'), 'O');
  assert.equal(resolveDocumentSequenceOrganizationCode('unknown-org'), null);
});

test('formatDocumentSequencePeriod returns YYMM format', () => {
  assert.equal(formatDocumentSequencePeriod(new Date('2026-06-15T00:00:00.000Z')), '2606');
});

test('normalizeDocumentSequenceProductType keeps explicit generic fallback', () => {
  assert.equal(normalizeDocumentSequenceProductType('Dock Door'), 'dock_door');
  assert.equal(normalizeDocumentSequenceProductType(''), 'all');
});
