const XLSX = require('xlsx');
const fs = require('fs');
const path = require('path');

const data = [
  {
    'Colaborador': 'colaborador_mde',
    'Periodo': '2026-06',
    'Hotel': 'EST-MDE',
    'Monto': 120000,
    'Cantidad': 10,
    'Id_Transaccion': 'TX-MDE-001'
  },
  {
    'Colaborador': 'lider_ctg',
    'Periodo': '2026-06',
    'Hotel': 'EST-CTG',
    'Monto': 2500000, // Anomaly trigger (value > 1,000,000)
    'Cantidad': 15,
    'Id_Transaccion': 'TX-CTG-002'
  }
];

const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, 'Sales Import');

// Ensure target directories exist
const dir = path.join(__dirname, '../public/templates');
if (!fs.existsSync(dir)) {
  fs.mkdirSync(dir, { recursive: true });
}

const outputPath = path.join(dir, 'demo_sales_data.xlsx');
XLSX.writeFile(wb, outputPath);
console.log(`Successfully generated demo spreadsheet at: ${outputPath}`);
