import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
  parseEnabled,
  parseKittyVisibility,
  parseMessageMax,
  parseMessageSource,
  parseMinDurationMs,
  parseNotificationAction,
} from "../src/parsers.ts";

describe("parsers", () => {
  it("parses message source including privacy mode", () => {
    assert.equal(parseMessageSource("assistant"), "assistant");
    assert.equal(parseMessageSource(" user "), "user");
    assert.equal(parseMessageSource("none"), "none");
    assert.equal(parseMessageSource("invalid"), "assistant");
  });

  it("parses and clamps numeric settings", () => {
    assert.equal(parseMessageMax(undefined), 80);
    assert.equal(parseMessageMax("12"), 12);
    assert.equal(parseMessageMax("-1"), 0);
    assert.equal(parseMessageMax("999"), 500);
    assert.equal(parseMessageMax("nope"), 80);
    assert.equal(parseMinDurationMs(undefined), 3_000);
    assert.equal(parseMinDurationMs("  "), 3_000);
    assert.equal(parseMinDurationMs("1.25"), 1_250);
    assert.equal(parseMinDurationMs("9999"), 3_600_000);
  });

  it("uses fail-safe defaults for boolean and Kitty behavior settings", () => {
    assert.equal(parseEnabled(undefined), true);
    assert.equal(parseEnabled("off"), false);
    assert.equal(parseEnabled("yes"), true);
    assert.equal(parseKittyVisibility(undefined), "always");
    assert.equal(parseKittyVisibility("always"), "always");
    assert.equal(parseKittyVisibility("unfocused"), "unfocused");
    assert.equal(parseKittyVisibility("invisible"), "invisible");
    assert.equal(parseKittyVisibility("invalid"), "always");
    assert.equal(parseNotificationAction("none"), "none");
    assert.equal(parseNotificationAction("invalid"), "focus");
  });
});
