var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.deleteMessagesForChannel = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _SqliteClient = require("../SqliteClient");
var deleteMessagesForChannel = exports.deleteMessagesForChannel = function () {
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref) {
    var cid, truncated_at, _ref$execute, execute, timestamp, query;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          cid = _ref.cid, truncated_at = _ref.truncated_at, _ref$execute = _ref.execute, execute = _ref$execute === void 0 ? true : _ref$execute;
          timestamp = truncated_at ? new Date(truncated_at).toISOString() : new Date().toISOString();
          query = ["DELETE FROM messages WHERE cid = ? AND createdAt <= ?", [cid, timestamp]];
          _SqliteClient.SqliteClient.logger == null || _SqliteClient.SqliteClient.logger('info', 'deleteMessagesForChannel', {
            cid: cid,
            execute: execute,
            truncated_at: truncated_at
          });
          if (!execute) {
            _context.next = 7;
            break;
          }
          _context.next = 7;
          return _SqliteClient.SqliteClient.executeSql.apply(null, query);
        case 7:
          return _context.abrupt("return", [query]);
        case 8:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function deleteMessagesForChannel(_x) {
    return _ref2.apply(this, arguments);
  };
}();
//# sourceMappingURL=deleteMessagesForChannel.js.map