import { resolveNotificationService } from "../../notifications/lib/notificationService.js";
import { buildFeatureNotificationFromType } from "../../notifications/lib/notificationBuilder.js";
import { notificationTypes } from "../notifications.js";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("sales");
const metadata = {
  event: "sales.quote.expiring",
  persistent: true,
  id: "sales:quote-expiring-notification"
};
async function handle(payload, ctx) {
  try {
    const notificationService = resolveNotificationService(ctx);
    const typeDef = notificationTypes.find((type) => type.type === "sales.quote.expiring");
    if (!typeDef) return;
    const notificationInput = buildFeatureNotificationFromType(typeDef, {
      requiredFeature: "sales.quotes.manage",
      bodyVariables: {
        quoteNumber: payload.quoteNumber,
        expiresAt: payload.expiresAt,
        daysUntilExpiry: String(payload.daysUntilExpiry),
        customerName: payload.customerName ?? ""
      },
      sourceEntityType: "sales:quote",
      sourceEntityId: payload.quoteId,
      linkHref: `/backend/sales/quotes/${payload.quoteId}`
    });
    await notificationService.createForFeature(notificationInput, {
      tenantId: payload.tenantId,
      organizationId: payload.organizationId ?? null
    });
  } catch (err) {
    logger.error("sales.quote-expiring-notification Failed to create notification", { err });
  }
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=quote-expiring-notification.js.map
