text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const pip_services3_commons_node_1 = require("pip-services3-commons-node");
  const pip_clients_msgdistribution_node_1 = require("pip-clients-msgdistribution-node");
  class MessageConnector {
      constructor(_logger, _messageResolver, _messageDistributionClient) {
          this._logger = _logger;
          this._messageResolver = _messageResolver;
          this._messageDistributionClient = _messageDistributionClient;
          if (_messageDistributionClient == null)
              this._logger.warn(null, 'Email or Message distribution client was not found. Invitation notifications are disabled');
      }
      sendInvitation(correlationId, message, invitation) {
          if (this._messageDistributionClient == null)
              return;
          if (message == null)
              return;
          let recipient = {
              id: invitation.invitee_id ? invitation.invitee_id : "",
              email: invitation.invitee_email,
              name: invitation.invitee_name,
              language: invitation.language
          };
          let parameters = pip_services3_commons_node_1.ConfigParams.fromTuples('invitee_name', invitation.invitee_name, 'invitee_email', invitation.invitee_email, 'org_id', invitation.org_id, 'org_name', invitation.org_name, 'create_time', invitation.create_time, 'creator_id', invitation.creator_id, 'creator_name', invitation.creator_name, 'expire_time', invitation.expire_time);
          this._messageDistributionClient.sendMessage(correlationId, recipient, message, parameters, pip_clients_msgdistribution_node_1.DeliveryMethodV1.Email, (err) => {
              if (err)
                  this._logger.error(correlationId, err, 'Failed to send message');
          });
      }
      sendAccessRequest(correlationId, message, invitation, organizationAdminIds) {
          if (this._messageDistributionClient == null)
              return;
          if (message == null)
              return;
          let parameters = pip_services3_commons_node_1.ConfigParams.fromTuples('invitee_name', invitation.invitee_name, 'invitee_email', invitation.invitee_email, 'org_id', invitation.org_id, 'org_name', invitation.org_name, 'create_time', invitation.create_time, 'creator_id', invitation.creator_id, 'creator_name', invitation.creator_name, 'expire_time', invitation.expire_time);
          this._messageDistributionClient.sendMessageToRecipients(correlationId, organizationAdminIds, null, message, parameters, pip_clients_msgdistribution_node_1.DeliveryMethodV1.All, (err) => {
              if (err)
                  this._logger.error(correlationId, err, 'Failed to send message');
          });
      }
  }
  exports.MessageConnector = MessageConnector;
  //# sourceMappingURL=MessageConnector.js.map