// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { test, expect, vi } from "vitest";
import { openLix } from "../lix/open-lix.js";
import { newLixFile } from "../lix/new-lix.js";
import { resolveChangeConflictBySelecting } from "./resolve-conflict-by-selecting.js";
test.skip("it should resolve a conflict and apply the changes", async () => {
    const mockSnapshots = [
        {
            id: "value1",
            content: {
                key: "test-key-1",
                value: "test-value-1",
            },
        },
        {
            id: "value2",
            content: {
                key: "test-key-2",
                value: "test-value-2",
            },
        },
    ];
    const mockChanges = [
        {
            plugin_key: "plugin1",
            schema_key: "mock",
            file_id: "mock",
            entity_id: "value1",
            snapshot_id: mockSnapshots[0].id,
        },
        {
            plugin_key: "plugin1",
            file_id: "mock",
            entity_id: "value2",
            schema_key: "mock",
            snapshot_id: mockSnapshots[1].id,
        },
    ];
    const mockPlugin = {
        key: "plugin1",
        applyChanges: vi.fn().mockResolvedValue({
            fileData: new TextEncoder().encode(JSON.stringify(mockSnapshots[0]?.content)),
        }),
    };
    const lix = await openLix({
        blob: await newLixFile(),
        providePlugins: [mockPlugin],
    });
    await lix.db
        .insertInto("file")
        .values({
        id: "mock",
        path: "/mock",
        data: new Uint8Array(),
    })
        .execute();
    const snapshots = await lix.db
        .insertInto("snapshot")
        .values(mockSnapshots.map((s) => {
        return { content: s.content };
    }))
        .returningAll()
        .execute();
    const changes = await lix.db
        .insertInto("change")
        .values(mockChanges)
        .returningAll()
        .execute();
    const changeSet0 = await lix.db
        .insertInto("change_set")
        .defaultValues()
        .returningAll()
        .executeTakeFirstOrThrow();
    const conflict = await lix.db
        .insertInto("change_conflict")
        .values({
        key: "mock",
        change_set_id: changeSet0.id,
    })
        .returningAll()
        .executeTakeFirstOrThrow();
    await resolveChangeConflictBySelecting({
        lix: lix,
        conflict: conflict,
        select: changes[0],
    });
    const resolvedConflict = await lix.db
        .selectFrom("change_conflict")
        .innerJoin("change_conflict_resolution", "change_conflict_resolution.change_conflict_id", "change_conflict.id")
        .where("id", "=", conflict.id)
        .selectAll()
        .executeTakeFirstOrThrow();
    // TODO QUEUE check if the replacement of file_internal was expected
    const fileAfterResolve = await lix.db
        .selectFrom("file")
        .selectAll()
        .where("id", "=", changes[0].file_id)
        .executeTakeFirstOrThrow();
    const parsed = JSON.parse(new TextDecoder().decode(fileAfterResolve.data));
    expect(parsed).toStrictEqual(snapshots[0].content);
    expect(resolvedConflict.resolved_change_id).toBe(changes[0].id);
});
//# sourceMappingURL=resolve-conflict-by-selecting.test.js.map