import pool from './db.js';

async function clearData() {
    try {
        console.log('Clearing all business data...');

        // Disable foreign key checks to allow truncation
        await pool.query('SET FOREIGN_KEY_CHECKS = 0');

        await pool.query('TRUNCATE TABLE documents');
        await pool.query('TRUNCATE TABLE receipts');
        await pool.query('TRUNCATE TABLE petty_cash');
        await pool.query('TRUNCATE TABLE expenses');
        await pool.query('TRUNCATE TABLE invoices');
        await pool.query('TRUNCATE TABLE quotations');
        await pool.query('TRUNCATE TABLE projects');
        await pool.query('TRUNCATE TABLE customers');

        // Re-enable foreign key checks
        await pool.query('SET FOREIGN_KEY_CHECKS = 1');

        console.log('All business data cleared successfully.');
        console.log('User accounts were preserved.');
        process.exit(0);
    } catch (error) {
        console.error('Error clearing data:', error);
        process.exit(1);
    }
}

clearData();
