import type { DiffStats } from '@/modules/shared-kernel/entities/diffStats/diffStats.js';
import type { DiffStatsFetchGateway } from '@/modules/shared-kernel/entities/diffStats/diffStatsFetch.gateway.js';

export class StubDiffStatsFetchGateway implements DiffStatsFetchGateway {
  private responses = new Map<number, DiffStats | null>();
  private failingMergeRequests = new Set<number>();
  fetchCallCount = 0;

  fetchDiffStats(_projectPath: string, mergeRequestNumber: number): DiffStats | null {
    this.fetchCallCount++;

    if (this.failingMergeRequests.has(mergeRequestNumber)) {
      throw new Error(`API error for MR ${mergeRequestNumber}`);
    }

    return this.responses.get(mergeRequestNumber) ?? null;
  }

  setResponse(mergeRequestNumber: number, diffStats: DiffStats | null): void {
    this.responses.set(mergeRequestNumber, diffStats);
  }

  setFailure(mergeRequestNumber: number): void {
    this.failingMergeRequests.add(mergeRequestNumber);
  }
}
