export type FrameworkKind =
  | 'laravel'
  | 'codeigniter'
  | 'react'
  | 'vue'
  | 'nuxt'
  | 'django'
  | 'rails'
  | 'symfony'
  | 'generic';

export interface AdapterCommand {
  command: string;
  args: string[];
  cwd: string;
}

/**
 * A FrameworkAdapter knows how to install, run, build, test, and lint a
 * specific kind of project. Generic workflow tools resolve one (or two, for
 * combined backend+frontend projects) via detect.ts and dispatch through
 * this interface instead of hardcoding any framework's CLI.
 */
export interface FrameworkAdapter {
  readonly kind: FrameworkKind;
  readonly label: string;
  readonly root: string;
  readonly packageManager?: string;

  installCommand(): AdapterCommand;
  devCommand(): AdapterCommand;
  buildCommand(): AdapterCommand | null;
  testCommand(extraArgs?: string[]): AdapterCommand | null;
  lintCommand(fix?: boolean): AdapterCommand | null;

  /** Matched against dev-server output to detect "ready" + extract the URL. */
  readyPattern(): RegExp;

  /** Metadata surfaced via the detect_framework tool and project.json resource. */
  describe(): Record<string, unknown>;
}

export type AdapterTarget = 'backend' | 'frontend';

export interface DetectedProject {
  backend: FrameworkAdapter | null;
  frontend: FrameworkAdapter | null;
  /** Convenience accessor: backend if present, else frontend, else the generic fallback. */
  primary: FrameworkAdapter;
}

/** One package/app inside a monorepo (or the single root project). */
export interface DetectedPackage {
  name: string;
  relativePath: string;
  absolutePath: string;
  detected: DetectedProject;
}

/** Workspace-level view: root plus zero or more packages. */
export interface DetectedWorkspace {
  root: string;
  packages: DetectedPackage[];
}
