import { describe, expect, it } from "vitest";
import {
  buildCargoHash,
  serializeAddress,
} from "@/modules/quote/cargo-hash";

const baseInput = {
  pickupSerialized: serializeAddress({
    street: "1234 Warehouse Blvd",
    city: "Los Angeles",
    state: "CA",
    zip: "90001",
    place_id: "ChIJ_pickup",
  }),
  deliverySerialized: serializeAddress({
    street: "5678 Distribution Dr",
    city: "Dallas",
    state: "TX",
    zip: "75201",
    place_id: "ChIJ_delivery",
  }),
  weightLb: 500,
  dimLIn: 48,
  dimWIn: 40,
  dimHIn: 48,
  palletCount: 2,
  cargoType: "general_freight",
};

describe("buildCargoHash", () => {
  it("相同入参 → 相同 hash", () => {
    const h1 = buildCargoHash(baseInput);
    const h2 = buildCargoHash(baseInput);
    expect(h1).toBe(h2);
    expect(h1).toHaveLength(32);
  });

  it("place_id 不同 → hash 不同", () => {
    const h1 = buildCargoHash(baseInput);
    const h2 = buildCargoHash({
      ...baseInput,
      pickupSerialized: serializeAddress({
        street: "1234 Warehouse Blvd",
        city: "Los Angeles",
        state: "CA",
        zip: "90001",
        place_id: "ChIJ_other",
      }),
    });
    expect(h1).not.toBe(h2);
  });

  it("service_level 不在 hash 中（cargo_type 相同则 hash 相同）", () => {
    const h1 = buildCargoHash(baseInput);
    const h2 = buildCargoHash({ ...baseInput, cargoType: "general_freight" });
    expect(h1).toBe(h2);
  });
});
