import type { AdapterCommand } from './types.js';
import { PhpFrameworkAdapter } from './phpBase.js';

export class CodeIgniterAdapter extends PhpFrameworkAdapter {
  readonly kind = 'codeigniter' as const;
  readonly label = 'CodeIgniter 4';

  devCommand(): AdapterCommand {
    return { command: 'php', args: ['spark', 'serve'], cwd: this.root };
  }

  buildCommand(): AdapterCommand | null {
    // CodeIgniter has no dedicated production-build step beyond a lean install;
    // callers that need config/route caching should extend this via `spark`.
    return { command: 'composer', args: ['install', '--no-dev', '--optimize-autoloader'], cwd: this.root };
  }

  readyPattern(): RegExp {
    // `php spark serve` prints: "CodeIgniter development server started on http://localhost:8080"
    return /CodeIgniter development server started on (https?:\/\/\S+)/i;
  }

  describe(): Record<string, unknown> {
    return {
      kind: this.kind,
      label: this.label,
      root: this.root,
      packageManager: this.packageManager,
      codeigniterVersion: this.composerJson?.require?.['codeigniter4/framework'] ?? null,
      devUrl: 'http://localhost:8080',
    };
  }
}
