import { describe, expect, it } from "vitest";
import {
  DEFAULT_EXPEDITED_DEMO,
  DEFAULT_FTL_FTL_EXPEDITED_DEMO,
  PRIORITY1_CANONICAL_PATHS,
} from "@/workers/rpa/priority1/demo-input";
import {
  validatePriority1FormConstraints,
} from "@/workers/rpa/priority1/form-constraints";

describe("priority1 form-constraints", () => {
  it("24 条 canonical 无硬限制违规", () => {
    const errors = PRIORITY1_CANONICAL_PATHS.flatMap((p) =>
      validatePriority1FormConstraints(p.input).filter((v) => v.severity === "error"),
    );
    expect(errors).toEqual([]);
  });

  it("Expedited Large 超过 10000 lb 报错", () => {
    const v = validatePriority1FormConstraints({
      ...DEFAULT_EXPEDITED_DEMO,
      expeditedTrailer: "large_straight",
      weightLb: "11000",
    });
    expect(v.some((x) => x.code === "WEIGHT_MAX")).toBe(true);
  });

  it("非 Large Straight 不可勾选 Liftgate", () => {
    const v = validatePriority1FormConstraints({
      ...DEFAULT_EXPEDITED_DEMO,
      expeditedTrailer: "sprinter_van",
      expeditedLiftgate: true,
    });
    expect(v.some((x) => x.code === "LIFTGATE_TRAILER")).toBe(true);
  });

  it("FTL 内嵌 Expedited Large 重量上限 10000", () => {
    const v = validatePriority1FormConstraints({
      ...DEFAULT_FTL_FTL_EXPEDITED_DEMO,
      ftlExpeditedTrailer: "large_straight",
      weightLb: "12000",
    });
    expect(v.some((x) => x.code === "WEIGHT_MAX")).toBe(true);
  });
});
