import { OrderCalculator, ProfitTableRow } from "@/utils";
import dayjs from "dayjs";

export class ProfitCalculationService {
  // 计算单车的利润数据

  static calculateOrderProfit(order: BusinessAPI.OrderVO): ProfitTableRow {
    // 车次
    const vehicleNo = `第${order.orderVehicle.vehicleNo || ""}车`;

    // 发货日期 - 从 orderShipList 获取
    const shippingDate = dayjs(order.orderVehicle.deliveryTime).format(
      "YYYY/MM/DD",
    );

    const orderCalculator = new OrderCalculator(order);
    // 计算产地成本
    const originCost = orderCalculator
      .getCostCalculator()
      .calculateMelonPurchaseCost();
    // 报价金额
    const quoteAmount = orderCalculator.getSalesAmount();
    // 计算利润
    const profit = orderCalculator.getNetProfit();

    return {
      vehicleNo,
      shippingDate,
      originCost,
      quoteAmount,
      profit,
    };
  }
}
