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

function copyDependencies() {
    const distPath = path.join(__dirname, 'dist', 'win-unpacked');
    const resourcesPath = path.join(distPath, 'resources');
    
    if (!fs.existsSync(distPath)) {
        console.log('Directorio dist no encontrado. Ejecuta primero: npm run build');
        return;
    }

    const sourceDllPaths = [
        'C:/RpaClaro/AutoItX3_x64.dll',
        'C:/Windows/System32/msvcr120.dll',
        'C:/Windows/System32/msvcp120.dll'
    ];

    const targetDllPath = path.join(distPath, 'dlls');
    
    if (!fs.existsSync(targetDllPath)) {
        fs.mkdirSync(targetDllPath, { recursive: true });
    }

    sourceDllPaths.forEach(sourcePath => {
        if (fs.existsSync(sourcePath)) {
            const fileName = path.basename(sourcePath);
            const targetPath = path.join(targetDllPath, fileName);
            
            try {
                fs.copyFileSync(sourcePath, targetPath);
                console.log(`✓ Copiado: ${fileName}`);
            } catch (error) {
                console.log(`✗ Error copiando ${fileName}: ${error.message}`);
            }
        }
    });

    console.log('✓ Script de copia de dependencias completado');
}

if (require.main === module) {
    copyDependencies();
}

module.exports = { copyDependencies };