"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PacketSequence = exports.GenesisState = void 0;
var _channel = require("./channel");
var _helpers = require("../../../../helpers");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } //@ts-nocheck
/** GenesisState defines the ibc channel submodule's genesis state. */

/** GenesisState defines the ibc channel submodule's genesis state. */

/**
 * PacketSequence defines the genesis type necessary to retrieve and store
 * next send and receive sequences.
 */

/**
 * PacketSequence defines the genesis type necessary to retrieve and store
 * next send and receive sequences.
 */

function createBaseGenesisState() {
  return {
    channels: [],
    acknowledgements: [],
    commitments: [],
    receipts: [],
    sendSequences: [],
    recvSequences: [],
    ackSequences: [],
    nextChannelSequence: _helpers.Long.UZERO,
    params: undefined
  };
}
var GenesisState = exports.GenesisState = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    var _iterator = _createForOfIteratorHelper(message.channels),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _channel.IdentifiedChannel.encode(v, writer.uint32(10).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var _iterator2 = _createForOfIteratorHelper(message.acknowledgements),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        _channel.PacketState.encode(_v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.commitments),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        _channel.PacketState.encode(_v2, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var _iterator4 = _createForOfIteratorHelper(message.receipts),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _v3 = _step4.value;
        _channel.PacketState.encode(_v3, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.sendSequences),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v4 = _step5.value;
        PacketSequence.encode(_v4, writer.uint32(42).fork()).ldelim();
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    var _iterator6 = _createForOfIteratorHelper(message.recvSequences),
      _step6;
    try {
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        var _v5 = _step6.value;
        PacketSequence.encode(_v5, writer.uint32(50).fork()).ldelim();
      }
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
    var _iterator7 = _createForOfIteratorHelper(message.ackSequences),
      _step7;
    try {
      for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
        var _v6 = _step7.value;
        PacketSequence.encode(_v6, writer.uint32(58).fork()).ldelim();
      }
    } catch (err) {
      _iterator7.e(err);
    } finally {
      _iterator7.f();
    }
    if (!message.nextChannelSequence.isZero()) {
      writer.uint32(64).uint64(message.nextChannelSequence);
    }
    if (message.params !== undefined) {
      _channel.Params.encode(message.params, writer.uint32(74).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseGenesisState();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.channels.push(_channel.IdentifiedChannel.decode(reader, reader.uint32()));
          break;
        case 2:
          message.acknowledgements.push(_channel.PacketState.decode(reader, reader.uint32()));
          break;
        case 3:
          message.commitments.push(_channel.PacketState.decode(reader, reader.uint32()));
          break;
        case 4:
          message.receipts.push(_channel.PacketState.decode(reader, reader.uint32()));
          break;
        case 5:
          message.sendSequences.push(PacketSequence.decode(reader, reader.uint32()));
          break;
        case 6:
          message.recvSequences.push(PacketSequence.decode(reader, reader.uint32()));
          break;
        case 7:
          message.ackSequences.push(PacketSequence.decode(reader, reader.uint32()));
          break;
        case 8:
          message.nextChannelSequence = reader.uint64();
          break;
        case 9:
          message.params = _channel.Params.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      channels: Array.isArray(object === null || object === void 0 ? void 0 : object.channels) ? object.channels.map(function (e) {
        return _channel.IdentifiedChannel.fromJSON(e);
      }) : [],
      acknowledgements: Array.isArray(object === null || object === void 0 ? void 0 : object.acknowledgements) ? object.acknowledgements.map(function (e) {
        return _channel.PacketState.fromJSON(e);
      }) : [],
      commitments: Array.isArray(object === null || object === void 0 ? void 0 : object.commitments) ? object.commitments.map(function (e) {
        return _channel.PacketState.fromJSON(e);
      }) : [],
      receipts: Array.isArray(object === null || object === void 0 ? void 0 : object.receipts) ? object.receipts.map(function (e) {
        return _channel.PacketState.fromJSON(e);
      }) : [],
      sendSequences: Array.isArray(object === null || object === void 0 ? void 0 : object.sendSequences) ? object.sendSequences.map(function (e) {
        return PacketSequence.fromJSON(e);
      }) : [],
      recvSequences: Array.isArray(object === null || object === void 0 ? void 0 : object.recvSequences) ? object.recvSequences.map(function (e) {
        return PacketSequence.fromJSON(e);
      }) : [],
      ackSequences: Array.isArray(object === null || object === void 0 ? void 0 : object.ackSequences) ? object.ackSequences.map(function (e) {
        return PacketSequence.fromJSON(e);
      }) : [],
      nextChannelSequence: (0, _helpers.isSet)(object.nextChannelSequence) ? _helpers.Long.fromValue(object.nextChannelSequence) : _helpers.Long.UZERO,
      params: (0, _helpers.isSet)(object.params) ? _channel.Params.fromJSON(object.params) : undefined
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    if (message.channels) {
      obj.channels = message.channels.map(function (e) {
        return e ? _channel.IdentifiedChannel.toJSON(e) : undefined;
      });
    } else {
      obj.channels = [];
    }
    if (message.acknowledgements) {
      obj.acknowledgements = message.acknowledgements.map(function (e) {
        return e ? _channel.PacketState.toJSON(e) : undefined;
      });
    } else {
      obj.acknowledgements = [];
    }
    if (message.commitments) {
      obj.commitments = message.commitments.map(function (e) {
        return e ? _channel.PacketState.toJSON(e) : undefined;
      });
    } else {
      obj.commitments = [];
    }
    if (message.receipts) {
      obj.receipts = message.receipts.map(function (e) {
        return e ? _channel.PacketState.toJSON(e) : undefined;
      });
    } else {
      obj.receipts = [];
    }
    if (message.sendSequences) {
      obj.sendSequences = message.sendSequences.map(function (e) {
        return e ? PacketSequence.toJSON(e) : undefined;
      });
    } else {
      obj.sendSequences = [];
    }
    if (message.recvSequences) {
      obj.recvSequences = message.recvSequences.map(function (e) {
        return e ? PacketSequence.toJSON(e) : undefined;
      });
    } else {
      obj.recvSequences = [];
    }
    if (message.ackSequences) {
      obj.ackSequences = message.ackSequences.map(function (e) {
        return e ? PacketSequence.toJSON(e) : undefined;
      });
    } else {
      obj.ackSequences = [];
    }
    message.nextChannelSequence !== undefined && (obj.nextChannelSequence = (message.nextChannelSequence || _helpers.Long.UZERO).toString());
    message.params !== undefined && (obj.params = message.params ? _channel.Params.toJSON(message.params) : undefined);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$channels, _object$acknowledgeme, _object$commitments, _object$receipts, _object$sendSequences, _object$recvSequences, _object$ackSequences;
    var message = createBaseGenesisState();
    message.channels = ((_object$channels = object.channels) === null || _object$channels === void 0 ? void 0 : _object$channels.map(function (e) {
      return _channel.IdentifiedChannel.fromPartial(e);
    })) || [];
    message.acknowledgements = ((_object$acknowledgeme = object.acknowledgements) === null || _object$acknowledgeme === void 0 ? void 0 : _object$acknowledgeme.map(function (e) {
      return _channel.PacketState.fromPartial(e);
    })) || [];
    message.commitments = ((_object$commitments = object.commitments) === null || _object$commitments === void 0 ? void 0 : _object$commitments.map(function (e) {
      return _channel.PacketState.fromPartial(e);
    })) || [];
    message.receipts = ((_object$receipts = object.receipts) === null || _object$receipts === void 0 ? void 0 : _object$receipts.map(function (e) {
      return _channel.PacketState.fromPartial(e);
    })) || [];
    message.sendSequences = ((_object$sendSequences = object.sendSequences) === null || _object$sendSequences === void 0 ? void 0 : _object$sendSequences.map(function (e) {
      return PacketSequence.fromPartial(e);
    })) || [];
    message.recvSequences = ((_object$recvSequences = object.recvSequences) === null || _object$recvSequences === void 0 ? void 0 : _object$recvSequences.map(function (e) {
      return PacketSequence.fromPartial(e);
    })) || [];
    message.ackSequences = ((_object$ackSequences = object.ackSequences) === null || _object$ackSequences === void 0 ? void 0 : _object$ackSequences.map(function (e) {
      return PacketSequence.fromPartial(e);
    })) || [];
    message.nextChannelSequence = object.nextChannelSequence !== undefined && object.nextChannelSequence !== null ? _helpers.Long.fromValue(object.nextChannelSequence) : _helpers.Long.UZERO;
    message.params = object.params !== undefined && object.params !== null ? _channel.Params.fromPartial(object.params) : undefined;
    return message;
  }
};
function createBasePacketSequence() {
  return {
    portId: "",
    channelId: "",
    sequence: _helpers.Long.UZERO
  };
}
var PacketSequence = exports.PacketSequence = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.portId !== "") {
      writer.uint32(10).string(message.portId);
    }
    if (message.channelId !== "") {
      writer.uint32(18).string(message.channelId);
    }
    if (!message.sequence.isZero()) {
      writer.uint32(24).uint64(message.sequence);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBasePacketSequence();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.portId = reader.string();
          break;
        case 2:
          message.channelId = reader.string();
          break;
        case 3:
          message.sequence = reader.uint64();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      portId: (0, _helpers.isSet)(object.portId) ? String(object.portId) : "",
      channelId: (0, _helpers.isSet)(object.channelId) ? String(object.channelId) : "",
      sequence: (0, _helpers.isSet)(object.sequence) ? _helpers.Long.fromValue(object.sequence) : _helpers.Long.UZERO
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.portId !== undefined && (obj.portId = message.portId);
    message.channelId !== undefined && (obj.channelId = message.channelId);
    message.sequence !== undefined && (obj.sequence = (message.sequence || _helpers.Long.UZERO).toString());
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$portId, _object$channelId;
    var message = createBasePacketSequence();
    message.portId = (_object$portId = object.portId) !== null && _object$portId !== void 0 ? _object$portId : "";
    message.channelId = (_object$channelId = object.channelId) !== null && _object$channelId !== void 0 ? _object$channelId : "";
    message.sequence = object.sequence !== undefined && object.sequence !== null ? _helpers.Long.fromValue(object.sequence) : _helpers.Long.UZERO;
    return message;
  }
};