const SellerNotifcations = require("../models/SellerNotifications");

exports.dispatchOrderNotification = async ({
  seller_company_id,
  notification_type = "Order",
  order_id,
  order_reference_no,
}) => {
  try {
    if (!seller_company_id || !order_id || !order_reference_no) {
      throw new Error("Missing required fields for order notification.");
    }

    const message = `You have received a new order with Reference No: ${order_reference_no}. Please review the order details and prepare for fulfillment.`;

    await SellerNotifcations.create({
      seller_company_id,
      notification_type,
      description: message,
      order_id,
      order_reference_no,
      is_read: false,
    });

    return true;
  } catch (err) {
    console.error("Failed to dispatch order notification:", err.message);
    return false;
  }
};
