import { simulateReadableStream } from "ai";
import { MockLanguageModelV2 } from "ai/test";
import { vi } from "vitest";
import { AiServiceFeatureFlags } from "../features.js";
// A properly formatted mock JWT with user_id in payload for tests that need JWT parsing
export const mockJwt = `header.${Buffer.from(JSON.stringify({
    user_id: "test-user-123",
    org_id: "test-org-456",
})).toString("base64")}.signature`;
export const mockPeer = {
    call: {
        aiPushMessage: vi.fn(),
        aiSetGenerationState: vi.fn(),
        aiPushPromptInterpretation: vi.fn(),
    },
    close: vi.fn(),
};
export const mockClark = {
    state: "Idle",
    context: { peer: mockPeer },
    getMetadata: vi.fn(),
    resetContext: vi.fn(),
    updateContext: vi.fn(),
    updateMetadata: vi.fn(),
    resetAllMetadata: vi.fn(),
    send: vi.fn(),
};
export const mockHandlerParams = {
    draftInterface: {
        createDraftFile: vi.fn(),
        getDraftDiff: vi.fn(),
    },
    appRootDirPath: "/test/app",
    fsOperationQueue: {
        add: vi.fn(),
        enqueue: vi.fn().mockImplementation(async (fn) => fn()),
    },
    templateRenderer: {
        render: vi.fn(),
    },
    signals: {
        emit: vi.fn(),
    },
    sourceTrackerInterface: {
        getElementToFilePathMap: vi.fn(),
        getElementToFilePath: vi.fn(),
        getElementToLocation: vi.fn(),
        setElementToLocation: vi.fn(),
        setElementToFilePath: vi.fn(),
        deleteElementToLocation: vi.fn(),
        deleteElementToFilePath: vi.fn(),
        getScopeDefinitionForPage: vi.fn(),
        isCustomComponent: vi.fn(),
    },
    appShell: {
        appRootDirPath: "/test/app",
        readFiles: vi.fn().mockReturnValue([
            {
                name: "test.ts",
                content: 'console.log("test");',
            },
        ]),
        runTypecheck: vi.fn(),
        runLinter: vi.fn(),
        warmLinterCache: vi.fn(),
        clearScratchDirectory: vi.fn(),
    },
    artifactProcessor: {
        process: vi.fn(),
        extractFileArtifacts: vi.fn().mockReturnValue([
            {
                name: "test.ts",
                content: 'console.log("test");',
            },
        ]),
        createArtifactContext: vi.fn().mockReturnValue({
            paths: ["test.ts"],
            content: "test file content",
        }),
    },
    clarkProvider: vi.fn().mockReturnValue(new MockLanguageModelV2({
        doStream: async () => ({
            stream: simulateReadableStream({
                chunks: [
                    { type: "text-delta", id: "1", delta: "Hello" },
                    { type: "text-delta", id: "2", delta: " world!" },
                    {
                        type: "finish",
                        finishReason: "stop",
                        logprobs: undefined,
                        usage: {
                            inputTokens: 13,
                            outputTokens: 10,
                            totalTokens: 23,
                        },
                    },
                ],
            }),
            request: { body: null },
            response: { headers: {} },
        }),
    })),
    integrationStore: {
        getOpenApiSpec: vi.fn(),
        getIntegrationForPromptContext: vi.fn(),
    },
    knowledgeManager: {
        loadFactsPromptSections: vi.fn().mockResolvedValue({
            systemPromptSection: "",
            userMessageSection: "",
            onDemandSkillIndex: "",
            facts: {
                org: [],
                user: [],
                integrations: {},
            },
        }),
        getNetNewFacts: vi.fn().mockReturnValue({
            org: [],
            user: [],
            integrations: {},
        }),
        hasAnyFacts: vi.fn().mockReturnValue(false),
        getFactById: vi.fn().mockReturnValue(undefined),
    },
    appContextStore: {
        componentSemanticsById: {},
        apiSemanticsByName: {},
        getComponent: vi.fn().mockReturnValue({}),
    },
    chatSessionStore: {
        getMessages: vi.fn(),
        newChat: vi.fn(),
        recordUser: vi.fn(),
        recordUserAcceptance: vi.fn(),
        recordUserRejection: vi.fn(),
        recordAssistant: vi.fn(),
        recordAssistantChangeInfo: vi.fn(),
        getLastUserMessage: vi.fn(),
    },
    features: AiServiceFeatureFlags.create(),
    llmProvider: {
        name: "test-provider",
        modelForTask: vi.fn().mockReturnValue(new MockLanguageModelV2({
            doStream: async () => ({
                stream: simulateReadableStream({
                    chunks: [
                        {
                            type: "finish",
                            finishReason: "stop",
                            logprobs: undefined,
                            usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
                        },
                    ],
                }),
                request: { body: null },
                response: { headers: {} },
            }),
        })),
    },
    logger: {
        info: vi.fn(),
        error: vi.fn(),
        debug: vi.fn(),
        warn: vi.fn(),
    },
};
//# sourceMappingURL=mocks.js.map