import { normalizeToConstitutionalChangeType, mapConstitutionalChangeTypeToDealerProfile } from '../common/utils/constitutionalNormalize.js';
import { ConstitutionalWorkflowService } from '../services/ConstitutionalWorkflowService.js';

describe('Constitutional alignment', () => {
  it('rejects legacy non-structure change types after scope tightening', () => {
    expect(normalizeToConstitutionalChangeType('Director Change')).toBeNull();
    expect(normalizeToConstitutionalChangeType('Ownership Transfer')).toBeNull();
    expect(normalizeToConstitutionalChangeType('Company Formation')).toBeNull();
  });

  it('maps supported structure change types to dealer profile', () => {
    expect(mapConstitutionalChangeTypeToDealerProfile('Proprietorship')).toBe('Proprietorship');
    expect(mapConstitutionalChangeTypeToDealerProfile('Partnership')).toBe('Partnership');
    expect(mapConstitutionalChangeTypeToDealerProfile('LLP')).toBe('LLP');
    expect(mapConstitutionalChangeTypeToDealerProfile('Private Limited')).toBe('Private Limited');
  });

  it('computes missing mandatory documents from uploaded checklist payload', () => {
    const completeDocs = [
      { documentType: 'GST Certificate' },
      { documentType: 'PAN Card' },
      { documentType: 'Aadhaar' },
      { documentType: 'Certificate of Incorporation' },
      { documentType: 'Business Purchase Agreement (BPA)' },
      { documentType: 'LLP Agreement' },
      { documentType: 'Cancelled Check' },
      { documentType: 'Declaration / Authorization Letter' }
    ];
    expect(ConstitutionalWorkflowService.getMissingMandatoryDocuments('LLP', completeDocs)).toEqual([]);

    const missingOne = completeDocs.filter((d) => d.documentType !== 'Business Purchase Agreement (BPA)');
    const missing = ConstitutionalWorkflowService.getMissingMandatoryDocuments('LLP', missingOne);
    expect(missing).toContain('Business Purchase Agreement (BPA)');
  });
});
