import { test as base, expect, type APIRequestContext } from "@playwright/test"
import { getAdminContext } from "./helpers/admin-api"
import { TEST_BASE_URL } from "../fixtures/test-constants"

const API_BASE = "/api"

type ApiFixtures = {
    api: APIRequestContext
    adminApi: APIRequestContext
}

export const test = base.extend<ApiFixtures>({
    api: async ({ request }, use) => {
        await use(request)
    },

    adminApi: async ({ baseURL }, use) => {
        const ctx = await getAdminContext(baseURL || TEST_BASE_URL)
        await use(ctx)
    },
})

export { expect, API_BASE }
