#!/usr/bin/env node

/**
 * Post-TSOA Generation Script
 * Fixes the multer file size limit in generated routes.ts
 * 
 * Run after tsoa:gen to update file size limits
 */

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

const ROUTES_FILE = path.join(__dirname, '../src/routes/routes.ts');
const OLD_LIMIT = '"fileSize":8388608';  // 8MB (tsoa default)
const NEW_LIMIT = '"fileSize":1073741824'; // 1GB

try {
    if (!fs.existsSync(ROUTES_FILE)) {
        console.error('Error: routes.ts not found at', ROUTES_FILE);
        process.exit(1);
    }

    let content = fs.readFileSync(ROUTES_FILE, 'utf8');
    
    if (content.includes(OLD_LIMIT)) {
        content = content.replace(OLD_LIMIT, NEW_LIMIT);
        fs.writeFileSync(ROUTES_FILE, content, 'utf8');
        console.log('✅ Updated multer file size limit to 1GB in routes.ts');
    } else if (content.includes(NEW_LIMIT)) {
        console.log('✅ Multer file size limit already set to 1GB');
    } else {
        console.warn('⚠️ Could not find multer fileSize config in routes.ts');
    }
} catch (error) {
    console.error('Error updating routes.ts:', error.message);
    process.exit(1);
}
