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("inbox_ops").child({ component: "proposal-notifier" });
const metadata = {
  event: "inbox_ops.proposal.created",
  persistent: true,
  id: "inbox_ops:proposal-notifier"
};
async function handle(payload, ctx) {
  try {
    const notificationService = resolveNotificationService(ctx);
    const typeDef = notificationTypes.find((t) => t.type === "inbox_ops.proposal.created");
    if (!typeDef) return;
    const notificationInput = buildFeatureNotificationFromType(typeDef, {
      requiredFeature: "inbox_ops.proposals.view",
      bodyVariables: {
        actionCount: String(payload.actionCount)
      },
      sourceEntityType: "inbox_ops:proposal",
      sourceEntityId: payload.proposalId,
      linkHref: `/backend/inbox-ops/proposals/${payload.proposalId}`
    });
    await notificationService.createForFeature(notificationInput, {
      tenantId: payload.tenantId,
      organizationId: payload.organizationId ?? null
    });
  } catch (err) {
    logger.error("Failed to create notification", { err });
    throw err;
  }
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=proposalNotifier.js.map
