import { describe, it, expect } from "vitest";
import { calculateThanSat, pillarOfYear } from "./than-sat";

describe("pillarOfYear", () => {
  it("1984 = Giáp Tý (mốc chuẩn)", () => {
    const p = pillarOfYear(1984);
    expect(p.can).toBe("Giáp");
    expect(p.chi).toBe("Tý");
  });

  it("1990 = Canh Ngọ", () => {
    const p = pillarOfYear(1990);
    expect(p.can).toBe("Canh");
    expect(p.chi).toBe("Ngọ");
  });

  it("2026 = Bính Ngọ", () => {
    const p = pillarOfYear(2026);
    expect(p.can).toBe("Bính");
    expect(p.chi).toBe("Ngọ");
  });

  it("1995 = Ất Hợi", () => {
    const p = pillarOfYear(1995);
    expect(p.can).toBe("Ất");
    expect(p.chi).toBe("Hợi");
  });
});

describe("calculateThanSat", () => {
  it("Giáp Tý (1984): Lộc=Dần (ĐB), Mã=Dần (ĐB), Quý=Sửu/Mùi", () => {
    const ts = calculateThanSat(1984);
    expect(ts.pillar.can).toBe("Giáp");
    expect(ts.loc.chi).toBe("Dần");
    expect(ts.loc.direction).toBe("Đông Bắc");
    // Tý → tam hợp Thân-Tý-Thìn → Mã ở Dần
    expect(ts.ma.chi).toBe("Dần");
    expect(ts.ma.direction).toBe("Đông Bắc");
    expect(ts.quy.chis).toEqual(["Sửu", "Mùi"]);
    expect(ts.quy.directions).toEqual(["Đông Bắc", "Tây Nam"]);
  });

  it("Bính Ngọ (2026): Lộc=Tỵ, Mã=Thân, Quý=Hợi/Dậu", () => {
    const ts = calculateThanSat(2026);
    expect(ts.loc.chi).toBe("Tỵ");
    expect(ts.loc.direction).toBe("Đông Nam");
    // Ngọ → Dần-Ngọ-Tuất → Mã ở Thân
    expect(ts.ma.chi).toBe("Thân");
    expect(ts.ma.direction).toBe("Tây Nam");
    expect(ts.quy.chis).toEqual(["Hợi", "Dậu"]);
    expect(ts.quy.directions).toEqual(["Tây Bắc", "Tây"]);
  });

  it("Canh Ngọ (1990): Lộc=Thân, Mã=Thân, Quý=Sửu/Mùi", () => {
    const ts = calculateThanSat(1990);
    expect(ts.loc.chi).toBe("Thân");
    expect(ts.loc.direction).toBe("Tây Nam");
    expect(ts.ma.chi).toBe("Thân");
    expect(ts.quy.chis).toEqual(["Sửu", "Mùi"]);
  });

  it("Tân Tỵ (2001): Lộc=Dậu, Mã=Hợi, Quý=Dần/Ngọ", () => {
    const ts = calculateThanSat(2001);
    expect(ts.pillar.can).toBe("Tân");
    expect(ts.pillar.chi).toBe("Tỵ");
    expect(ts.loc.chi).toBe("Dậu");
    expect(ts.loc.direction).toBe("Tây");
    // Tỵ → Tỵ-Dậu-Sửu → Mã ở Hợi
    expect(ts.ma.chi).toBe("Hợi");
    expect(ts.ma.direction).toBe("Tây Bắc");
    expect(ts.quy.chis).toEqual(["Dần", "Ngọ"]);
  });

  it("Nhâm Tý (1972): Lộc=Hợi, Mã=Dần, Quý=Tỵ/Mão", () => {
    const ts = calculateThanSat(1972);
    expect(ts.loc.chi).toBe("Hợi");
    expect(ts.ma.chi).toBe("Dần");
    expect(ts.quy.chis).toEqual(["Tỵ", "Mão"]);
  });
});
