/**
 * Integration Test Helper
 *
 * Integration tests require a running backend: docker-compose up
 *
 * To run integration tests:
 *   RUN_INTEGRATION_TESTS=true npm run test
 *
 * By default, integration tests are skipped in the regular test run.
 */

export const runIntegrationTests = process.env.RUN_INTEGRATION_TESTS === 'true'

// Type for Jest's describe function (simplied, avoids needing @types/jest at build time)
type DescribeFn = {
    (name: string, fn: () => void): void
    skip: (name: string, fn: () => void) => void
}

// Declare global describe from Jest (only available in test environment)
declare const describe: DescribeFn

/**
 * Use this instead of `describe` for integration test suites that require a backend.
 * Tests will be skipped unless RUN_INTEGRATION_TESTS=true.
 */
export const describeIntegration = runIntegrationTests ? describe : describe.skip

/**
 * Backend URL from environment or default localhost
 */
export const BACKEND_URL = (() => {
    if (!process.env.NEXT_PUBLIC_HOST_URL) {
        console.warn('[mizan/testing] NEXT_PUBLIC_HOST_URL not set, falling back to http://localhost')
    }
    return process.env.NEXT_PUBLIC_HOST_URL || 'http://localhost'
})()

/**
 * WebSocket URL derived from backend URL
 */
export const WS_URL = BACKEND_URL.replace(/^http/, 'ws') + '/ws/'
