import { defineConfig, devices } from "@playwright/test"
import { env, AUTH_STORAGE_STATE } from "./support/env"

export default defineConfig({
  testDir: "./specs",
  fullyParallel: false, // specs share warehouse/item reference data via the ledger - keep runs serial per file
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 1 : 0,
  // Multiple workers hit the local dev backend concurrently across spec files and it can't
  // take it: confirmed reference-data GETs (e.g. /warehouses) intermittently 500 under 2+
  // workers against a plain `dotnet run` + local Postgres, and pass every time at workers: 1.
  // Bump this only against a backend that can actually take concurrent load (a real CI service
  // container, not a single dev-mode process).
  workers: 1,
  reporter: [["html", { open: "never" }], ["list"]],
  timeout: 45_000,
  expect: { timeout: 10_000 },
  use: {
    baseURL: env.baseUrl,
    trace: "on-first-retry",
    screenshot: "only-on-failure",
    video: "retain-on-failure",
  },
  projects: [
    {
      name: "setup",
      testMatch: /global\.setup\.ts/,
    },
    {
      name: "chromium",
      use: { ...devices["Desktop Chrome"], storageState: AUTH_STORAGE_STATE },
      dependencies: ["setup"],
    },
  ],
})
