import type { Adapter } from "../../src/adapter";
import type { AdapterResult } from "../../src/schema";

/** Test-only adapter: returns a fixed payload, or throws when configured to fail. */
export class FixtureAdapter implements Adapter {
  readonly id: string;
  readonly interval: number;
  private failNext = false;

  constructor(id = "fixture", interval = 1000) {
    this.id = id;
    this.interval = interval;
  }

  failOnNextPoll(): void {
    this.failNext = true;
  }

  async poll(): Promise<AdapterResult> {
    if (this.failNext) {
      this.failNext = false;
      throw new Error("fixture adapter forced failure");
    }
    return {
      items: [
        {
          id: `${this.id}-item-1`,
          source: this.id,
          severity: "info",
          kind: "progress",
          title: "fixture item",
          detail: "fixture detail",
          ts: new Date().toISOString(),
          actions: [],
        },
      ],
      panels: [
        {
          id: `${this.id}-panel-1`,
          ts: new Date().toISOString(),
          data: { ok: true },
        },
      ],
    };
  }
}
