/**
 * Convert kebab-case to camelCase
 */
function toCamelCase(str: string): string {
  return str.replace(/-([a-z0-9])/g, (_: string, char: string) => char.toUpperCase());
}

/**
 * Generate the index.ts file that exports all generated rules
 */
export function generateIndex(ruleNames: string[]): string {
  const imports = ruleNames
    .map((name) => {
      const camel = toCamelCase(name);
      return `import ${camel} from './${name}';`;
    })
    .join('\n');

  const rulesObject = ruleNames
    .map((name) => {
      const camel = toCamelCase(name);
      return `  '${name}': ${camel},`;
    })
    .join('\n');

  const namedExports = ruleNames.map(toCamelCase).join(', ');

  return `// Generated by @harness-engineering/linter-gen
// Do not edit manually - regenerate from harness-linter.yml

${imports}

export const rules = {
${rulesObject}
};

export { ${namedExports} };
`;
}
