import { wfmFileService } from '../services/wfmFile.service';
import logger from '../utils/logger';
import dotenv from 'dotenv';
import path from 'path';

// Load environment variables
dotenv.config();

async function testOfficialCSVGeneration() {
    try {
        console.log('Starting WFM Official CSV Generation Test...');
        
        const officialData = [{
            TRNS_UNIQ_NO: '1342774290',
            CLAIM_NUMBER: 'CLI000012833733',
            INV_NUMBER: 'INV007593742231',
            DEALER_CODE: '6059',
            IO_NUMBER: '439887',
            CLAIM_DOC_TYP: 'ZMBS',
            CLAIM_DATE: '20190627',
            CLAIM_AMT: 3931.539,
            GST_AMT: '185.00',
            GST_PERCENTAG: 18
        }];

        const fileName = `OFFICIAL_TEST_${Date.now()}.csv`;
        const filePath = await wfmFileService.generateIncomingClaimCSV(officialData, fileName);
        
        console.log(`✅ Success! Official CSV generated at: ${filePath}`);
        
        // Verify file existence and content
        const fs = require('fs');
        if (fs.existsSync(filePath)) {
            console.log('File existence verified on disk.');
            const content = fs.readFileSync(filePath, 'utf8');
            console.log('--- CSV Content ---');
            console.log(content);
            console.log('-------------------');
        } else {
            console.error('❌ Error: File not found on disk!');
        }

    } catch (error) {
        console.error('❌ Test failed:', error);
    }
}

testOfficialCSVGeneration();
