import assert from 'node:assert/strict';
import {
    getResignationStatusForStage,
    getTerminationStatusForStage,
    normalizeClearanceStatus,
    normalizeFnFStatus,
    normalizeTerminationCurrentStage,
    getLegacyTerminationRowFixes
} from '../src/common/utils/offboardingStatus.js';
import { getJointRoundCutoffMsFromTimeline } from '../src/common/utils/terminationJointReviewRound.util.js';

assert.equal(normalizeFnFStatus('settled'), 'Completed');
assert.equal(normalizeFnFStatus('finance approval'), 'Finance Approval');

assert.equal(getResignationStatusForStage('ASM'), 'ASM Review');
assert.equal(getResignationStatusForStage('F&F Initiated'), 'F&F Initiated');

assert.equal(getTerminationStatusForStage('Submitted'), 'Submitted');
assert.equal(getTerminationStatusForStage('Terminated'), 'Terminated');

assert.equal(
    normalizeTerminationCurrentStage('Personal Hearing'),
    'Evaluation of Dealer SCN Response'
);
assert.deepEqual(getLegacyTerminationRowFixes({ currentStage: 'Personal Hearing', status: 'Personal Hearing Pending' }), {
    currentStage: 'Evaluation of Dealer SCN Response',
    status: 'SCN Response Evaluation Pending'
});

const reconsiderTimeline = [
    { action: 'Approved', targetStage: 'NBH Final Approval', timestamp: new Date('2024-01-01').toISOString() },
    {
        action: 'Sent for Reconsideration',
        targetStage: 'Evaluation of Dealer SCN Response',
        timestamp: new Date('2025-06-15T12:00:00.000Z').toISOString()
    }
];
assert.equal(
    getJointRoundCutoffMsFromTimeline(reconsiderTimeline, 'scn_response_eval'),
    new Date('2025-06-15T12:00:00.000Z').getTime()
);

assert.equal(normalizeClearanceStatus('Cleared', 0), 'NOC Submitted');
assert.equal(normalizeClearanceStatus('Cleared', 100), 'Dues Pending');
assert.equal(normalizeClearanceStatus('Pending', 0), 'Pending');

console.log('Offboarding status normalization checks passed.');
