import { describe, it, expect } from "vitest";
import {
  lifePath,
  expressionNumber,
  soulUrge,
  personalityNumber,
  birthdayNumber,
  maturityNumber,
  personalYear,
  PERSONAL_YEAR_GUIDE,
} from "./numerology";

describe("personalityNumber", () => {
  it("returns single digit or master", () => {
    const n = personalityNumber("Nguyen Van A");
    expect(n).toBeGreaterThanOrEqual(1);
    expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33]).toContain(n);
  });

  it("returns valid value for typical names", () => {
    // Personality and SoulUrge can occasionally reduce to same digit
    // (numerologically valid). Assert both produce valid output.
    const name = "Tran Hoang Nam";
    const p = personalityNumber(name);
    const s = soulUrge(name);
    expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33]).toContain(p);
    expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33]).toContain(s);
  });
});

describe("birthdayNumber", () => {
  it("returns reduced single digit for normal day", () => {
    expect(birthdayNumber(15)).toBe(6); // 1+5=6
    expect(birthdayNumber(28)).toBe(1); // 2+8=10 → 1
  });

  it("preserves master 11 and 22", () => {
    expect(birthdayNumber(11)).toBe(11);
    expect(birthdayNumber(22)).toBe(22);
  });
});

describe("maturityNumber", () => {
  it("returns reduced sum of life path + expression", () => {
    expect(maturityNumber(5, 3)).toBe(8);
    expect(maturityNumber(7, 6)).toBe(4); // 13 → 4
  });
});

describe("personalYear", () => {
  it("computes for known case", () => {
    // Birth 15/8, year 2026 → 1+5+8+2+0+2+6 = 24 → 6
    expect(personalYear(8, 15, 2026)).toBe(6);
  });

  it("returns single digit or master", () => {
    const n = personalYear(7, 4, 2027);
    expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33]).toContain(n);
  });
});

describe("PERSONAL_YEAR_GUIDE", () => {
  it("has entries for 1-9", () => {
    for (let i = 1; i <= 9; i++) {
      expect(PERSONAL_YEAR_GUIDE[i]).toBeDefined();
      expect(PERSONAL_YEAR_GUIDE[i].theme).toBeTruthy();
      expect(PERSONAL_YEAR_GUIDE[i].advice).toBeTruthy();
    }
  });
});
