var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.deleteReaction = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _createDeleteQuery = require("../sqlite-utils/createDeleteQuery");
var _createUpdateQuery = require("../sqlite-utils/createUpdateQuery");
var _SqliteClient = require("../SqliteClient");
var deleteReaction = exports.deleteReaction = function () {
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref) {
    var _ref$execute, execute, message, reaction, queries, stringifiedNewReactionGroups;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _ref$execute = _ref.execute, execute = _ref$execute === void 0 ? true : _ref$execute, message = _ref.message, reaction = _ref.reaction;
          queries = [];
          if (message) {
            _context.next = 4;
            break;
          }
          return _context.abrupt("return", []);
        case 4:
          queries.push((0, _createDeleteQuery.createDeleteQuery)('reactions', {
            messageId: reaction.message_id,
            type: reaction.type,
            userId: reaction.user_id
          }));
          stringifiedNewReactionGroups = JSON.stringify(message.reaction_groups);
          queries.push((0, _createUpdateQuery.createUpdateQuery)('messages', {
            reactionGroups: stringifiedNewReactionGroups
          }, {
            id: message.id
          }));
          _SqliteClient.SqliteClient.logger == null || _SqliteClient.SqliteClient.logger('info', 'deleteReaction', {
            reaction: reaction
          });
          if (!execute) {
            _context.next = 11;
            break;
          }
          _context.next = 11;
          return _SqliteClient.SqliteClient.executeSqlBatch(queries);
        case 11:
          return _context.abrupt("return", queries);
        case 12:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function deleteReaction(_x) {
    return _ref2.apply(this, arguments);
  };
}();
//# sourceMappingURL=deleteReaction.js.map