import { describe, it, expect } from "vitest";
import { analyzeFengShui } from "./bat-trach";
import { buildRoomPlacement } from "./room-placement";

describe("buildRoomPlacement", () => {
  // Born 1990 male → cung Càn (Tây Tứ Mệnh, hành Kim)
  const result = analyzeFengShui({ year: 1990, gender: "Nam" });

  it("returns all 8 rooms", () => {
    const guide = buildRoomPlacement(result);
    expect(guide).toHaveLength(8);
    const keys = guide.map((g) => g.key).sort();
    expect(keys).toEqual([
      "ban-lam-viec",
      "ban-tho",
      "bep",
      "cua-chinh",
      "kho-cau-thang",
      "phong-khach",
      "phong-ngu",
      "ve-sinh",
    ]);
  });

  it("cửa chính best direction is Sinh Khí of the cung", () => {
    const guide = buildRoomPlacement(result);
    const cua = guide.find((g) => g.key === "cua-chinh")!;
    expect(cua.bestDirections[0].fortune).toBe("Sinh Khí");
    expect(cua.bestDirections.length).toBeGreaterThan(0);
  });

  it("vệ sinh prefers hung directions", () => {
    const guide = buildRoomPlacement(result);
    const wc = guide.find((g) => g.key === "ve-sinh")!;
    // First preferred is some hung fortune
    expect(["Tuyệt Mệnh", "Ngũ Quỷ", "Lục Sát", "Họa Hại"]).toContain(wc.bestDirections[0].fortune);
    // Should NOT include any good fortune
    for (const d of wc.bestDirections) {
      expect(d.isAuspicious).toBe(false);
    }
  });

  it("phòng ngủ avoids Lục Sát / Họa Hại", () => {
    const guide = buildRoomPlacement(result);
    const bed = guide.find((g) => g.key === "phong-ngu")!;
    for (const d of bed.bestDirections) {
      expect(["Diên Niên", "Thiên Y", "Phục Vị"]).toContain(d.fortune);
    }
  });

  it("bếp avoid list contains hung directions (toạ hung)", () => {
    const guide = buildRoomPlacement(result);
    const bep = guide.find((g) => g.key === "bep")!;
    // Body of the stove should be at hung — those are listed under worstDirections
    for (const d of bep.worstDirections) {
      expect(d.isAuspicious).toBe(false);
    }
  });
});
