import { describe, expect, it } from "vitest";
import { applyMarkupToPriority1Lines } from "@/modules/priority1/quote-storage";
import type { Priority1QuoteLine } from "@/workers/rpa/priority1/quote-extract";

const sampleLine: Priority1QuoteLine = {
  rank: 1,
  carrier: "XPO",
  carrierCode: "XPOL",
  totalUsd: 500,
  transitDays: 5,
  deliveryDate: null,
  expirationDate: null,
  serviceLevel: "Standard",
  quoteId: null,
  caboUrl: null,
  source: "visible-dom",
};

describe("applyMarkupToPriority1Lines", () => {
  it("applies percent markup per customer rule", () => {
    const marked = applyMarkupToPriority1Lines([sampleLine], {
      type: "percent",
      percent: 10,
      fixedAmount: 0,
    });
    expect(marked[0]!.markup_amount).toBe(50);
    expect(marked[0]!.final_total_usd).toBe(550);
  });

  it("applies fixed markup per line", () => {
    const marked = applyMarkupToPriority1Lines([sampleLine], {
      type: "fixed",
      percent: 0,
      fixedAmount: 25,
    });
    expect(marked[0]!.markup_amount).toBe(25);
    expect(marked[0]!.final_total_usd).toBe(525);
  });
});
