import { Bytes } from "@zwave-js/shared";
import { MockController, MockNode, } from "@zwave-js/testing";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { createDefaultMockControllerBehaviors, createDefaultMockNodeBehaviors, } from "../../Testing.js";
import { createAndStartDriverWithMockPort, } from "../driver/DriverMock.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export function prepareDriver(cacheDir = path.join(__dirname, "cache"), logToFile = false, additionalOptions = {}) {
    // Skipping the bootloader check speeds up tests a lot
    additionalOptions.testingHooks ??= {};
    additionalOptions.testingHooks.skipFirmwareIdentification =
        additionalOptions.bootloaderMode === "recover"
            || additionalOptions.bootloaderMode == undefined;
    const logConfig = additionalOptions.logConfig ?? {};
    if (logToFile) {
        logConfig.enabled = true;
        logConfig.logToFile = true;
        logConfig.filename = path.join(cacheDir, "logs", "zwavejs_%DATE%.log");
        logConfig.level ??= "debug";
    }
    return createAndStartDriverWithMockPort({
        ...additionalOptions,
        logConfig,
        securityKeys: {
            S0_Legacy: Bytes.from("0102030405060708090a0b0c0d0e0f10", "hex"),
            S2_Unauthenticated: Bytes.from("11111111111111111111111111111111", "hex"),
            S2_Authenticated: Bytes.from("22222222222222222222222222222222", "hex"),
            S2_AccessControl: Bytes.from("33333333333333333333333333333333", "hex"),
        },
        storage: {
            ...additionalOptions.storage,
            cacheDir: cacheDir,
            lockDir: path.join(cacheDir, "locks"),
        },
    });
}
export async function prepareMocks(mockPort, serial, controller = {}, nodes = []) {
    const mockController = await MockController.create({
        homeId: 0x7e570001,
        ownNodeId: 1,
        ...controller,
        mockPort,
        serial,
    });
    // Apply default behaviors that are required for interacting with the driver correctly
    mockController.defineBehavior(...createDefaultMockControllerBehaviors());
    const mockNodes = [];
    for (const node of nodes) {
        const mockNode = await MockNode.create({
            ...node,
            controller: mockController,
        });
        mockController.addNode(mockNode);
        mockNodes.push(mockNode);
        // Apply default behaviors that are required for interacting with the driver correctly
        mockNode.defineBehavior(...createDefaultMockNodeBehaviors());
    }
    return { mockController, mockNodes };
}
//# sourceMappingURL=integrationTestSuiteShared.js.map