import { test as base } from 'playwright-bdd';
import { createBdd } from 'playwright-bdd';
import type { APIResponse } from '@playwright/test';

export interface ApiTestState {
  lastResponse: APIResponse | null;
  lastBody: any;
  lastStatus: number | null;
  baseUrl: string;
  /** Arbitrary scenario-local storage (e.g. created quest ID). */
  context: Record<string, any>;
}

export const test = base.extend<{ apiState: ApiTestState }>({ // eslint-disable-line
  apiState: async ({}, use) => {
    await use({
      lastResponse: null,
      lastBody: null,
      lastStatus: null,
      baseUrl: process.env.SUT_URL || 'http://localhost',
      context: {},
    });
  },
});

export const { Given, When, Then, Before, After } = createBdd(test);
