import { ExecArgs } from "@medusajs/framework/types";
import orderMondialRelayShipmentSubscriber from "../subscribers/order-mondialrelay-shipment";

export default async function mondialRelayBackfillOrder({ container }: ExecArgs) {
  const fulfillmentId = String(process.env.FULFILLMENT_ID || "").trim();
  const orderId = String(process.env.ORDER_ID || "").trim();

  if (!fulfillmentId) {
    throw new Error("Missing FULFILLMENT_ID env var. Example: FULFILLMENT_ID=ful_xxx");
  }

  await orderMondialRelayShipmentSubscriber({
    container,
    event: {
      name: "order.fulfillment_created",
      data: { id: orderId, order_id: orderId, fulfillment_id: fulfillmentId },
      metadata: {},
      options: {},
      source: "manual-backfill",
    },
  } as any);
}
