import { describe, expect, test } from "bun:test";
import {
	getAiDisabledMessage,
	isAdminAiEnabled,
	isAiFlagEnabled,
	isClientAiEnabled,
} from "@/lib/ai-feature-flags";

describe("AI feature flags", () => {
	test("AI admin flag defaults to enabled when unset", () => {
		expect(isAdminAiEnabled({})).toBe(true);
	});

	test("AI admin flag disables routes when explicitly false", () => {
		expect(isAdminAiEnabled({ AI_ENABLED: "false" })).toBe(false);
		expect(isAdminAiEnabled({ AI_ENABLED: "0" })).toBe(false);
	});

	test("AI client flag follows NEXT_PUBLIC_AI_ENABLED before server fallback", () => {
		expect(
			isClientAiEnabled({ NEXT_PUBLIC_AI_ENABLED: "false", AI_ENABLED: "true" }),
		).toBe(false);
	});

	test("truthy and falsy parsing remains explicit and predictable", () => {
		expect(isAiFlagEnabled("yes")).toBe(true);
		expect(isAiFlagEnabled("off")).toBe(false);
		expect(isAiFlagEnabled("unexpected-value")).toBe(true);
	});

	test("disabled message explains the admin-controlled state", () => {
		expect(getAiDisabledMessage().toLowerCase()).toContain("disabled");
		expect(getAiDisabledMessage().toLowerCase()).toContain("administrator");
	});
});
