import { describe, expect, it } from "vitest";
import {
  listNights,
  nightsBetween,
  rangesAreAdjacent,
  rangesOverlap,
} from "@/domain/date-ranges";

describe("date ranges", () => {
  it("allows adjacent stays", () => {
    expect(
      rangesAreAdjacent(
        { checkIn: "2026-08-01", checkOut: "2026-08-05" },
        { checkIn: "2026-08-05", checkOut: "2026-08-08" }
      )
    ).toBe(true);

    expect(
      rangesOverlap(
        { checkIn: "2026-08-01", checkOut: "2026-08-05" },
        { checkIn: "2026-08-05", checkOut: "2026-08-08" }
      )
    ).toBe(false);
  });

  it("rejects overlapping stays", () => {
    expect(
      rangesOverlap(
        { checkIn: "2026-08-01", checkOut: "2026-08-06" },
        { checkIn: "2026-08-05", checkOut: "2026-08-08" }
      )
    ).toBe(true);
  });

  it("lists the occupied nights in a half-open range", () => {
    expect(
      listNights({ checkIn: "2026-08-01", checkOut: "2026-08-04" })
    ).toEqual(["2026-08-01", "2026-08-02", "2026-08-03"]);
    expect(nightsBetween({ checkIn: "2026-08-01", checkOut: "2026-08-04" })).toBe(3);
  });
});
