/**
 * Abstract stack adapter — defines the lifecycle contract for E2E test stacks.
 *
 * Each concrete adapter (Tauri, Electrobun) implements binary discovery,
 * WebDriver setup/teardown, and optional PTY daemon management.
 */

import type { ChildProcess } from 'node:child_process';
import type { TestFixture } from '../infra/fixtures.ts';

export interface StackCapabilities {
  /** WebDriver capability object for WDIO */
  capabilities: Record<string, unknown>;
}

export abstract class StackAdapter {
  /** Human-readable stack name (e.g. 'tauri', 'electrobun') */
  abstract readonly name: string;

  /** WebDriver port for this stack */
  abstract readonly port: number;

  /** Resolve absolute path to the built binary */
  abstract getBinaryPath(): string;

  /** Data directory for test isolation */
  abstract getDataDir(fixture: TestFixture): string;

  /** Build WDIO capabilities object for this stack */
  abstract getCapabilities(fixture: TestFixture): StackCapabilities;

  /** Spawn the WebDriver process (tauri-driver, WebKitWebDriver, etc.) */
  abstract setupDriver(): Promise<ChildProcess>;

  /** Kill the WebDriver process */
  abstract teardownDriver(driver: ChildProcess): void;

  /** Optional: start PTY daemon before tests (Electrobun only) */
  async startPtyDaemon?(): Promise<ChildProcess>;

  /** Optional: stop PTY daemon after tests */
  stopPtyDaemon?(daemon: ChildProcess): void;
}
