import { config } from '../../config.js';
import { detectProject } from '../../lib/frameworks/detect.js';
import { CodeIgniterAdapter } from '../../lib/frameworks/codeigniter.js';

export function requireCodeIgniter(): CodeIgniterAdapter {
  const detected = detectProject(config.workspaceRoot);
  if (detected.backend instanceof CodeIgniterAdapter) {
    return detected.backend;
  }
  throw new Error(
    'No CodeIgniter 4 project detected in WORKSPACE_ROOT. ' +
      'Expected composer.json with codeigniter4/framework (or a spark file) at the workspace root.',
  );
}
