import type { AgentDeviceRuntime } from '../../../runtime-contract.ts';
import type {
  BoundRuntimeCommand,
  DiffSnapshotCommandOptions,
  RuntimeCommand,
  ScreenshotCommandOptions,
  SnapshotCommandOptions,
} from '../../runtime-types.ts';
import {
  diffScreenshotCommand,
  type DiffScreenshotCommandOptions,
  type DiffScreenshotCommandResult,
} from './diff-screenshot.ts';
import { screenshotCommand, type ScreenshotCommandResult } from './screenshot.ts';
import {
  diffSnapshotCommand,
  snapshotCommand,
  type DiffSnapshotCommandResult,
  type SnapshotCommandResult,
} from './snapshot.ts';

export type CaptureCommands = {
  screenshot: RuntimeCommand<ScreenshotCommandOptions, ScreenshotCommandResult>;
  diffScreenshot: RuntimeCommand<DiffScreenshotCommandOptions, DiffScreenshotCommandResult>;
  snapshot: RuntimeCommand<SnapshotCommandOptions, SnapshotCommandResult>;
  diffSnapshot: RuntimeCommand<DiffSnapshotCommandOptions, DiffSnapshotCommandResult>;
};

export type BoundCaptureCommands = {
  screenshot: BoundRuntimeCommand<ScreenshotCommandOptions, ScreenshotCommandResult>;
  diffScreenshot: BoundRuntimeCommand<DiffScreenshotCommandOptions, DiffScreenshotCommandResult>;
  snapshot: BoundRuntimeCommand<SnapshotCommandOptions, SnapshotCommandResult>;
  diffSnapshot: BoundRuntimeCommand<DiffSnapshotCommandOptions, DiffSnapshotCommandResult>;
};

export const captureCommands: CaptureCommands = {
  screenshot: screenshotCommand,
  diffScreenshot: diffScreenshotCommand,
  snapshot: snapshotCommand,
  diffSnapshot: diffSnapshotCommand,
};

export function bindCaptureCommands(runtime: AgentDeviceRuntime): BoundCaptureCommands {
  return {
    screenshot: (options) => captureCommands.screenshot(runtime, options),
    diffScreenshot: (options) => captureCommands.diffScreenshot(runtime, options),
    snapshot: (options) => captureCommands.snapshot(runtime, options),
    diffSnapshot: (options) => captureCommands.diffSnapshot(runtime, options),
  };
}
