import fs from 'fs';
import path from 'path';
import { servicePath, serviceTemplate } from './service.config';

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

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

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

fs.writeFileSync(filePath, serviceTemplate(className));
console.log(`✅ Service created at ${servicePath}/${className}Service.ts`);
