"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RegisteredPayee = exports.RegisteredCounterpartyPayee = exports.GenesisState = exports.ForwardRelayerAddress = exports.FeeEnabledChannel = void 0;
var _fee = require("./fee");
var _channel = require("../../../core/channel/v1/channel");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
var _helpers = require("../../../../helpers");
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 ICS29 fee middleware genesis state */

/** GenesisState defines the ICS29 fee middleware genesis state */

/** FeeEnabledChannel contains the PortID & ChannelID for a fee enabled channel */

/** FeeEnabledChannel contains the PortID & ChannelID for a fee enabled channel */

/** RegisteredPayee contains the relayer address and payee address for a specific channel */

/** RegisteredPayee contains the relayer address and payee address for a specific channel */

/**
 * RegisteredCounterpartyPayee contains the relayer address and counterparty payee address for a specific channel (used
 * for recv fee distribution)
 */

/**
 * RegisteredCounterpartyPayee contains the relayer address and counterparty payee address for a specific channel (used
 * for recv fee distribution)
 */

/** ForwardRelayerAddress contains the forward relayer address and PacketId used for async acknowledgements */

/** ForwardRelayerAddress contains the forward relayer address and PacketId used for async acknowledgements */

function createBaseGenesisState() {
  return {
    identifiedFees: [],
    feeEnabledChannels: [],
    registeredPayees: [],
    registeredCounterpartyPayees: [],
    forwardRelayers: []
  };
}
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.identifiedFees),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _fee.IdentifiedPacketFees.encode(v, writer.uint32(10).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var _iterator2 = _createForOfIteratorHelper(message.feeEnabledChannels),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        FeeEnabledChannel.encode(_v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.registeredPayees),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        RegisteredPayee.encode(_v2, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var _iterator4 = _createForOfIteratorHelper(message.registeredCounterpartyPayees),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _v3 = _step4.value;
        RegisteredCounterpartyPayee.encode(_v3, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.forwardRelayers),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v4 = _step5.value;
        ForwardRelayerAddress.encode(_v4, writer.uint32(42).fork()).ldelim();
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    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.identifiedFees.push(_fee.IdentifiedPacketFees.decode(reader, reader.uint32()));
          break;
        case 2:
          message.feeEnabledChannels.push(FeeEnabledChannel.decode(reader, reader.uint32()));
          break;
        case 3:
          message.registeredPayees.push(RegisteredPayee.decode(reader, reader.uint32()));
          break;
        case 4:
          message.registeredCounterpartyPayees.push(RegisteredCounterpartyPayee.decode(reader, reader.uint32()));
          break;
        case 5:
          message.forwardRelayers.push(ForwardRelayerAddress.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      identifiedFees: Array.isArray(object === null || object === void 0 ? void 0 : object.identifiedFees) ? object.identifiedFees.map(function (e) {
        return _fee.IdentifiedPacketFees.fromJSON(e);
      }) : [],
      feeEnabledChannels: Array.isArray(object === null || object === void 0 ? void 0 : object.feeEnabledChannels) ? object.feeEnabledChannels.map(function (e) {
        return FeeEnabledChannel.fromJSON(e);
      }) : [],
      registeredPayees: Array.isArray(object === null || object === void 0 ? void 0 : object.registeredPayees) ? object.registeredPayees.map(function (e) {
        return RegisteredPayee.fromJSON(e);
      }) : [],
      registeredCounterpartyPayees: Array.isArray(object === null || object === void 0 ? void 0 : object.registeredCounterpartyPayees) ? object.registeredCounterpartyPayees.map(function (e) {
        return RegisteredCounterpartyPayee.fromJSON(e);
      }) : [],
      forwardRelayers: Array.isArray(object === null || object === void 0 ? void 0 : object.forwardRelayers) ? object.forwardRelayers.map(function (e) {
        return ForwardRelayerAddress.fromJSON(e);
      }) : []
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    if (message.identifiedFees) {
      obj.identifiedFees = message.identifiedFees.map(function (e) {
        return e ? _fee.IdentifiedPacketFees.toJSON(e) : undefined;
      });
    } else {
      obj.identifiedFees = [];
    }
    if (message.feeEnabledChannels) {
      obj.feeEnabledChannels = message.feeEnabledChannels.map(function (e) {
        return e ? FeeEnabledChannel.toJSON(e) : undefined;
      });
    } else {
      obj.feeEnabledChannels = [];
    }
    if (message.registeredPayees) {
      obj.registeredPayees = message.registeredPayees.map(function (e) {
        return e ? RegisteredPayee.toJSON(e) : undefined;
      });
    } else {
      obj.registeredPayees = [];
    }
    if (message.registeredCounterpartyPayees) {
      obj.registeredCounterpartyPayees = message.registeredCounterpartyPayees.map(function (e) {
        return e ? RegisteredCounterpartyPayee.toJSON(e) : undefined;
      });
    } else {
      obj.registeredCounterpartyPayees = [];
    }
    if (message.forwardRelayers) {
      obj.forwardRelayers = message.forwardRelayers.map(function (e) {
        return e ? ForwardRelayerAddress.toJSON(e) : undefined;
      });
    } else {
      obj.forwardRelayers = [];
    }
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$identifiedFee, _object$feeEnabledCha, _object$registeredPay, _object$registeredCou, _object$forwardRelaye;
    var message = createBaseGenesisState();
    message.identifiedFees = ((_object$identifiedFee = object.identifiedFees) === null || _object$identifiedFee === void 0 ? void 0 : _object$identifiedFee.map(function (e) {
      return _fee.IdentifiedPacketFees.fromPartial(e);
    })) || [];
    message.feeEnabledChannels = ((_object$feeEnabledCha = object.feeEnabledChannels) === null || _object$feeEnabledCha === void 0 ? void 0 : _object$feeEnabledCha.map(function (e) {
      return FeeEnabledChannel.fromPartial(e);
    })) || [];
    message.registeredPayees = ((_object$registeredPay = object.registeredPayees) === null || _object$registeredPay === void 0 ? void 0 : _object$registeredPay.map(function (e) {
      return RegisteredPayee.fromPartial(e);
    })) || [];
    message.registeredCounterpartyPayees = ((_object$registeredCou = object.registeredCounterpartyPayees) === null || _object$registeredCou === void 0 ? void 0 : _object$registeredCou.map(function (e) {
      return RegisteredCounterpartyPayee.fromPartial(e);
    })) || [];
    message.forwardRelayers = ((_object$forwardRelaye = object.forwardRelayers) === null || _object$forwardRelaye === void 0 ? void 0 : _object$forwardRelaye.map(function (e) {
      return ForwardRelayerAddress.fromPartial(e);
    })) || [];
    return message;
  }
};
function createBaseFeeEnabledChannel() {
  return {
    portId: "",
    channelId: ""
  };
}
var FeeEnabledChannel = exports.FeeEnabledChannel = {
  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);
    }
    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 = createBaseFeeEnabledChannel();
    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;
        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) : ""
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.portId !== undefined && (obj.portId = message.portId);
    message.channelId !== undefined && (obj.channelId = message.channelId);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$portId, _object$channelId;
    var message = createBaseFeeEnabledChannel();
    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 : "";
    return message;
  }
};
function createBaseRegisteredPayee() {
  return {
    channelId: "",
    relayer: "",
    payee: ""
  };
}
var RegisteredPayee = exports.RegisteredPayee = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.channelId !== "") {
      writer.uint32(10).string(message.channelId);
    }
    if (message.relayer !== "") {
      writer.uint32(18).string(message.relayer);
    }
    if (message.payee !== "") {
      writer.uint32(26).string(message.payee);
    }
    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 = createBaseRegisteredPayee();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.channelId = reader.string();
          break;
        case 2:
          message.relayer = reader.string();
          break;
        case 3:
          message.payee = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      channelId: (0, _helpers.isSet)(object.channelId) ? String(object.channelId) : "",
      relayer: (0, _helpers.isSet)(object.relayer) ? String(object.relayer) : "",
      payee: (0, _helpers.isSet)(object.payee) ? String(object.payee) : ""
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.channelId !== undefined && (obj.channelId = message.channelId);
    message.relayer !== undefined && (obj.relayer = message.relayer);
    message.payee !== undefined && (obj.payee = message.payee);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$channelId2, _object$relayer, _object$payee;
    var message = createBaseRegisteredPayee();
    message.channelId = (_object$channelId2 = object.channelId) !== null && _object$channelId2 !== void 0 ? _object$channelId2 : "";
    message.relayer = (_object$relayer = object.relayer) !== null && _object$relayer !== void 0 ? _object$relayer : "";
    message.payee = (_object$payee = object.payee) !== null && _object$payee !== void 0 ? _object$payee : "";
    return message;
  }
};
function createBaseRegisteredCounterpartyPayee() {
  return {
    channelId: "",
    relayer: "",
    counterpartyPayee: ""
  };
}
var RegisteredCounterpartyPayee = exports.RegisteredCounterpartyPayee = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.channelId !== "") {
      writer.uint32(10).string(message.channelId);
    }
    if (message.relayer !== "") {
      writer.uint32(18).string(message.relayer);
    }
    if (message.counterpartyPayee !== "") {
      writer.uint32(26).string(message.counterpartyPayee);
    }
    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 = createBaseRegisteredCounterpartyPayee();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.channelId = reader.string();
          break;
        case 2:
          message.relayer = reader.string();
          break;
        case 3:
          message.counterpartyPayee = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      channelId: (0, _helpers.isSet)(object.channelId) ? String(object.channelId) : "",
      relayer: (0, _helpers.isSet)(object.relayer) ? String(object.relayer) : "",
      counterpartyPayee: (0, _helpers.isSet)(object.counterpartyPayee) ? String(object.counterpartyPayee) : ""
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.channelId !== undefined && (obj.channelId = message.channelId);
    message.relayer !== undefined && (obj.relayer = message.relayer);
    message.counterpartyPayee !== undefined && (obj.counterpartyPayee = message.counterpartyPayee);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$channelId3, _object$relayer2, _object$counterpartyP;
    var message = createBaseRegisteredCounterpartyPayee();
    message.channelId = (_object$channelId3 = object.channelId) !== null && _object$channelId3 !== void 0 ? _object$channelId3 : "";
    message.relayer = (_object$relayer2 = object.relayer) !== null && _object$relayer2 !== void 0 ? _object$relayer2 : "";
    message.counterpartyPayee = (_object$counterpartyP = object.counterpartyPayee) !== null && _object$counterpartyP !== void 0 ? _object$counterpartyP : "";
    return message;
  }
};
function createBaseForwardRelayerAddress() {
  return {
    address: "",
    packetId: undefined
  };
}
var ForwardRelayerAddress = exports.ForwardRelayerAddress = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.address !== "") {
      writer.uint32(10).string(message.address);
    }
    if (message.packetId !== undefined) {
      _channel.PacketId.encode(message.packetId, writer.uint32(18).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 = createBaseForwardRelayerAddress();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.address = reader.string();
          break;
        case 2:
          message.packetId = _channel.PacketId.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      address: (0, _helpers.isSet)(object.address) ? String(object.address) : "",
      packetId: (0, _helpers.isSet)(object.packetId) ? _channel.PacketId.fromJSON(object.packetId) : undefined
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.address !== undefined && (obj.address = message.address);
    message.packetId !== undefined && (obj.packetId = message.packetId ? _channel.PacketId.toJSON(message.packetId) : undefined);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$address;
    var message = createBaseForwardRelayerAddress();
    message.address = (_object$address = object.address) !== null && _object$address !== void 0 ? _object$address : "";
    message.packetId = object.packetId !== undefined && object.packetId !== null ? _channel.PacketId.fromPartial(object.packetId) : undefined;
    return message;
  }
};