import { z } from "zod";
import { SalesOrder } from "../../../../data/entities.js";
import { extractCustomerName } from "../helpers.js";
import { makeDashboardWidgetRoute } from "../../../../widgets/dashboard/makeDashboardWidgetRoute.js";
const orderItemSchema = z.object({
  id: z.string().uuid(),
  orderNumber: z.string(),
  status: z.string().nullable(),
  fulfillmentStatus: z.string().nullable(),
  paymentStatus: z.string().nullable(),
  customerName: z.string().nullable(),
  customerEntityId: z.string().uuid().nullable(),
  netAmount: z.string(),
  grossAmount: z.string(),
  currency: z.string().nullable(),
  createdAt: z.string()
});
const { GET, metadata, openApi } = makeDashboardWidgetRoute({
  entity: SalesOrder,
  cacheId: "sales:new-orders",
  cacheTags: ["widget-data:sales:orders"],
  feature: "sales.widgets.new-orders",
  itemSchema: orderItemSchema,
  errorPrefix: "sales.widgets.newOrders",
  openApi: {
    summary: "New orders dashboard widget",
    description: "Fetches recently created sales orders for the dashboard widget with a configurable date period.",
    getSummary: "Fetch recently created sales orders",
    itemDescription: "List of recent orders",
    errorFallback: "Failed to load orders"
  },
  mapItem: (order) => ({
    id: order.id,
    orderNumber: order.orderNumber,
    status: order.status ?? null,
    fulfillmentStatus: order.fulfillmentStatus ?? null,
    paymentStatus: order.paymentStatus ?? null,
    customerName: extractCustomerName(order.customerSnapshot) ?? null,
    customerEntityId: order.customerEntityId ?? null,
    netAmount: order.grandTotalNetAmount ?? "0",
    grossAmount: order.grandTotalGrossAmount ?? "0",
    currency: order.currencyCode ?? null,
    createdAt: order.createdAt ? order.createdAt.toISOString() : (/* @__PURE__ */ new Date()).toISOString()
  })
});
export {
  GET,
  metadata,
  openApi
};
//# sourceMappingURL=route.js.map
