import { describe, expect, it } from "vitest";
import { loadConfig } from "../src/config.js";

describe("ADB configuration", () => {
  it("is disabled by default", () => {
    expect(loadConfig({ NODE_ENV: "test" }).adb).toEqual({
      enabled: false,
      executable: "adb",
      serial: null,
      timeoutMs: 3_000
    });
  });

  it("supports automatic discovery or a constrained pinned serial when enabled", () => {
    expect(loadConfig({ NODE_ENV: "test", ADB_ENABLED: "true" }).adb).toMatchObject({ enabled: true, serial: null });
    expect(() =>
      loadConfig({ NODE_ENV: "test", ADB_ENABLED: "true", ADB_SERIAL: "serial; shell command" })
    ).toThrow();
    expect(loadConfig({ NODE_ENV: "test", ADB_ENABLED: "true", ADB_SERIAL: "10.0.0.10:5555" }).adb).toMatchObject({
      enabled: true,
      serial: "10.0.0.10:5555"
    });
  });

  it("keeps automatic network management disabled by default", () => {
    expect(loadConfig({ NODE_ENV: "test" }).network).toEqual({
      enabled: false,
      statusPath: "/var/lib/pi-car-companion/network-status.json",
      commandPath: "/var/lib/pi-car-companion/network-command.json",
      configurationRequestPath: "/var/lib/pi-car-companion/network-configuration-request.json",
      activityPath: "/var/lib/pi-car-companion/network-activity.json"
    });
  });
});
