import { describe, expect, it } from "vitest";
import { createAllocationDragState, type AllocationDragStateLike } from "./timelineAllocationDragState.js";

describe("timelineAllocationDragState", () => {
  it("defaults scope and mutation ids for whole-allocation drags", () => {
    expect(
      createAllocationDragState<AllocationDragStateLike<"move", "allocation" | "segment">, "move", "allocation" | "segment">({
        mode: "move",
        allocationId: "alloc-1",
        projectId: "project-1",
        projectName: "Alpha",
        resourceId: null,
        startDate: new Date("2025-01-01T00:00:00.000Z"),
        endDate: new Date("2025-01-05T00:00:00.000Z"),
        startMouseX: 320,
      }),
    ).toEqual({
      isActive: true,
      mode: "move",
      scope: "allocation",
      allocationId: "alloc-1",
      mutationAllocationId: "alloc-1",
      projectId: "project-1",
      projectName: "Alpha",
      resourceId: null,
      allocationStartDate: new Date("2025-01-01T00:00:00.000Z"),
      allocationEndDate: new Date("2025-01-05T00:00:00.000Z"),
      originalStartDate: new Date("2025-01-01T00:00:00.000Z"),
      originalEndDate: new Date("2025-01-05T00:00:00.000Z"),
      currentStartDate: new Date("2025-01-01T00:00:00.000Z"),
      currentEndDate: new Date("2025-01-05T00:00:00.000Z"),
      startMouseX: 320,
      pointerDeltaX: 0,
      daysDelta: 0,
    });
  });

  it("preserves explicit mutation ids and segment boundaries for fragment drags", () => {
    expect(
      createAllocationDragState<
        AllocationDragStateLike<"resize-end", "allocation" | "segment">,
        "resize-end",
        "allocation" | "segment"
      >({
        mode: "resize-end",
        scope: "segment",
        allocationId: "alloc-1",
        mutationAllocationId: "alloc-fragment-2",
        projectId: "project-1",
        projectName: "Alpha",
        resourceId: "resource-4",
        startDate: new Date("2025-01-03T00:00:00.000Z"),
        endDate: new Date("2025-01-04T00:00:00.000Z"),
        allocationStartDate: new Date("2025-01-01T00:00:00.000Z"),
        allocationEndDate: new Date("2025-01-07T00:00:00.000Z"),
        startMouseX: 144,
      }),
    ).toMatchObject({
      mode: "resize-end",
      scope: "segment",
      mutationAllocationId: "alloc-fragment-2",
      resourceId: "resource-4",
      allocationStartDate: new Date("2025-01-01T00:00:00.000Z"),
      allocationEndDate: new Date("2025-01-07T00:00:00.000Z"),
    });
  });
});
