import { pino } from 'pino';
import { vi } from 'vitest';
import { defaultNodeJSNavigatorContextProvider } from '../app/navigator-context-provider.js';
import { stateKey } from '../app/state-key.js';
function mockLogger(logger) {
    return Object.assign(logger, {
        debug: vi.fn(),
        info: vi.fn(),
        warn: vi.fn(),
        error: vi.fn(),
        fatal: vi.fn(),
    });
}
export function mockRelay() {
    return {
        emit: vi.fn(),
        getMeta: vi.fn().mockReturnValue({ clientId: 'test' }),
        off: vi.fn(),
        on: vi.fn(),
        updateConfig: vi.fn(),
        version: 'test',
    };
}
export function buildMockCoreEngine(initialState) {
    const state = initialState;
    return {
        state,
        // @ts-expect-error testing purposes
        dispatch: vi.fn(),
        addReducers: vi.fn(),
        disableAnalytics: vi.fn(),
        enableAnalytics: vi.fn(),
        logger: mockLogger(pino({ level: 'silent' })),
        relay: mockRelay(),
        store: {
            // @ts-expect-error testing purposes
            dispatch: vi.fn(),
            getState: vi.fn(),
            replaceReducer: vi.fn(),
            subscribe: vi.fn(),
            [Symbol.observable]: vi.fn(),
        },
        subscribe: vi.fn(),
        navigatorContext: defaultNodeJSNavigatorContextProvider(),
    };
}
export function buildMockCoreEngineNext(initialState) {
    const state = initialState;
    return {
        [stateKey]: state,
        configuration: state.configuration,
        // @ts-expect-error testing purposes
        dispatch: vi.fn(),
        addReducers: vi.fn(),
        disableAnalytics: vi.fn(),
        enableAnalytics: vi.fn(),
        logger: mockLogger(pino({ level: 'silent' })),
        relay: mockRelay(),
        subscribe: vi.fn(),
        navigatorContext: defaultNodeJSNavigatorContextProvider(),
    };
}
export function buildMockSearchEngine(initialState) {
    return {
        ...buildMockCoreEngine(initialState),
        executeFirstSearch: vi.fn(),
        executeFirstSearchAfterStandaloneSearchBoxRedirect: vi.fn(),
    };
}
export function buildMockCaseAssistEngine(initialState) {
    return {
        ...buildMockCoreEngine(initialState),
    };
}
export function buildMockCommerceEngine(initialState) {
    return {
        ...buildMockCoreEngineNext(initialState),
        configuration: {
            ...initialState.configuration,
        },
    };
}
export function buildMockInsightEngine(initialState) {
    return {
        ...buildMockCoreEngine(initialState),
        executeFirstSearch: vi.fn(),
    };
}
export function buildMockRecommendationEngine(initialState) {
    return {
        ...buildMockCoreEngine(initialState),
    };
}
export function buildMockSSRSearchEngine(initialState) {
    const engine = buildMockSearchEngine(initialState);
    return {
        ...engine,
        waitForSearchCompletedAction: vi.fn(),
    };
}
export function buildMockSSRCommerceEngine(initialState) {
    const engine = buildMockCommerceEngine(initialState);
    return {
        ...engine,
        waitForRequestCompletedAction: vi.fn(),
    };
}
