// scripts/make-controller.ts
import fs from 'fs';
import path from 'path';
import { controllerPath, controllerTemplate } from './controller.config';

const rawName = process.argv[2];
if (!rawName) {
  console.error('❌ Please provide a controller name: npm run make:controller Name');
  process.exit(1);
}

const className = rawName.charAt(0).toUpperCase() + rawName.slice(1);
const filePath = path.resolve(__dirname, `../${controllerPath}/${className}Controller.ts`);

if (fs.existsSync(filePath)) {
  console.error(`❌ Controller already exists at ${filePath}`);
  process.exit(1);
}

fs.writeFileSync(filePath, controllerTemplate(className));
console.log(`✅ Controller created at ${controllerPath}/${className}Controller.ts`);
