const notifier = require('./userNotifier')

/**
 * Server part of server to client communication implementation.
 *
 * Please do not forget before use to:
 * - get up and running RabbitMQ
 * - create `user-notify` topic exchange
 * - get up and running `rabbitmq-ub-router` and `rabbitmq-jwt-issuer` services
 * - configure `application.customSettings.rabbitMQ` section
 * - configure `uiSettings.adminUI.amqpNotificationUrl`
 *
 * @module notification
 * @memberOf module:@unitybase/messaging
 */
module.exports = {
  /**
   * Send broadcast notification, to all connected clients
   * @method broadcast
   * @param {string} topic
   *   Message topic.
   *   name of the notification source
   *   this should be unique name to be able for client to distinguish the source of notification message
   * @param {object} message
   *   the message to send
   *   any value is converted to JSON string before sending
   * @return {number} Event ID
   */
  broadcast: notifier.broadcast,

  /**
   * Send notification to a particular user (subject).
   * @method notifyUser
   * @param {number|number[]|undefined} subjectIDs
   *   If not specified, will be passed to `Session.uData.userID`.
   *   subjectID of the message recipient: UnityBase `userID` OR `roleID` or `groupID`
   *   If ORG model is used, could also be `staffUnitID` or `departmentID` or `organizationID`,
   * @param {object} message
   *   The event data object to send, value is converted to JSON string before sending
   * @param {string} [subTopic]
   *   name of the notification source
   *   this should be unique name to be able for client to distinguish the source of notification message
   * @return {number} Event ID
   */
  notifyUser: notifier.notifyUser,

  /**
   * Send a notification about change to client
   * @method entityEvent
   * @param {string} entityName
   * @param {number} instanceID
   * @param {object} message
   * @param {UBNotifyEntityEventOptions} [options]
   * @return {number}
   */
  entityEvent: notifier.entityEvent
}