import { describe, expect, it } from "vitest";
import {
  applyMarkupToFlockLines,
  buildFlockStoredQuotes,
  parseFlockStoredQuotes,
} from "@/modules/flock/quote-storage";
import type { FlockQuoteLine } from "@/workers/rpa/flock/types";

const lines: FlockQuoteLine[] = [
  {
    tier: "flock_direct",
    serviceLevel: "guaranteed",
    rateOption: "fastest",
    carrier: "Flock Freight",
    label: "FlockDirect®",
    totalUsd: 1000,
    transitDays: "4",
    transitDescription: "4 days",
  },
  {
    tier: "standard",
    serviceLevel: "standard",
    rateOption: "lowest",
    carrier: "Flock Freight",
    label: "Standard",
    totalUsd: 500,
    transitDays: "3-4",
    transitDescription: "3-4 days",
  },
];

describe("flock quote storage", () => {
  it("按百分比加价", () => {
    const marked = applyMarkupToFlockLines(lines, {
      type: "percent",
      percent: 10,
      fixedAmount: 0,
    });
    expect(marked[0]!.final_total_usd).toBe(1100);
    expect(marked[1]!.final_total_usd).toBe(550);
  });

  it("序列化与解析", () => {
    const stored = buildFlockStoredQuotes(
      lines,
      { type: "percent", percent: 0, fixedAmount: 0 },
      "FRG-TEST",
    );
    expect(stored.provider).toBe("flock");
    expect(parseFlockStoredQuotes(stored)?.reference).toBe("FRG-TEST");
    expect(parseFlockStoredQuotes({ provider: "priority1", lines: [] })).toBeNull();
  });
});
