"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IdentifiedGenesisMetadata = exports.GenesisState = exports.GenesisMetadata = void 0;
var _client = require("./client");
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 client submodule's genesis state. */

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

/**
 * GenesisMetadata defines the genesis type for metadata that clients may return
 * with ExportMetadata
 */

/**
 * GenesisMetadata defines the genesis type for metadata that clients may return
 * with ExportMetadata
 */

/**
 * IdentifiedGenesisMetadata has the client metadata with the corresponding
 * client id.
 */

/**
 * IdentifiedGenesisMetadata has the client metadata with the corresponding
 * client id.
 */

function createBaseGenesisState() {
  return {
    clients: [],
    clientsConsensus: [],
    clientsMetadata: [],
    params: undefined,
    createLocalhost: false,
    nextClientSequence: _helpers.Long.UZERO
  };
}
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.clients),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _client.IdentifiedClientState.encode(v, writer.uint32(10).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var _iterator2 = _createForOfIteratorHelper(message.clientsConsensus),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        _client.ClientConsensusStates.encode(_v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.clientsMetadata),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        IdentifiedGenesisMetadata.encode(_v2, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    if (message.params !== undefined) {
      _client.Params.encode(message.params, writer.uint32(34).fork()).ldelim();
    }
    if (message.createLocalhost === true) {
      writer.uint32(40).bool(message.createLocalhost);
    }
    if (!message.nextClientSequence.isZero()) {
      writer.uint32(48).uint64(message.nextClientSequence);
    }
    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.clients.push(_client.IdentifiedClientState.decode(reader, reader.uint32()));
          break;
        case 2:
          message.clientsConsensus.push(_client.ClientConsensusStates.decode(reader, reader.uint32()));
          break;
        case 3:
          message.clientsMetadata.push(IdentifiedGenesisMetadata.decode(reader, reader.uint32()));
          break;
        case 4:
          message.params = _client.Params.decode(reader, reader.uint32());
          break;
        case 5:
          message.createLocalhost = reader.bool();
          break;
        case 6:
          message.nextClientSequence = reader.uint64();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      clients: Array.isArray(object === null || object === void 0 ? void 0 : object.clients) ? object.clients.map(function (e) {
        return _client.IdentifiedClientState.fromJSON(e);
      }) : [],
      clientsConsensus: Array.isArray(object === null || object === void 0 ? void 0 : object.clientsConsensus) ? object.clientsConsensus.map(function (e) {
        return _client.ClientConsensusStates.fromJSON(e);
      }) : [],
      clientsMetadata: Array.isArray(object === null || object === void 0 ? void 0 : object.clientsMetadata) ? object.clientsMetadata.map(function (e) {
        return IdentifiedGenesisMetadata.fromJSON(e);
      }) : [],
      params: (0, _helpers.isSet)(object.params) ? _client.Params.fromJSON(object.params) : undefined,
      createLocalhost: (0, _helpers.isSet)(object.createLocalhost) ? Boolean(object.createLocalhost) : false,
      nextClientSequence: (0, _helpers.isSet)(object.nextClientSequence) ? _helpers.Long.fromValue(object.nextClientSequence) : _helpers.Long.UZERO
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    if (message.clients) {
      obj.clients = message.clients.map(function (e) {
        return e ? _client.IdentifiedClientState.toJSON(e) : undefined;
      });
    } else {
      obj.clients = [];
    }
    if (message.clientsConsensus) {
      obj.clientsConsensus = message.clientsConsensus.map(function (e) {
        return e ? _client.ClientConsensusStates.toJSON(e) : undefined;
      });
    } else {
      obj.clientsConsensus = [];
    }
    if (message.clientsMetadata) {
      obj.clientsMetadata = message.clientsMetadata.map(function (e) {
        return e ? IdentifiedGenesisMetadata.toJSON(e) : undefined;
      });
    } else {
      obj.clientsMetadata = [];
    }
    message.params !== undefined && (obj.params = message.params ? _client.Params.toJSON(message.params) : undefined);
    message.createLocalhost !== undefined && (obj.createLocalhost = message.createLocalhost);
    message.nextClientSequence !== undefined && (obj.nextClientSequence = (message.nextClientSequence || _helpers.Long.UZERO).toString());
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$clients, _object$clientsConsen, _object$clientsMetada, _object$createLocalho;
    var message = createBaseGenesisState();
    message.clients = ((_object$clients = object.clients) === null || _object$clients === void 0 ? void 0 : _object$clients.map(function (e) {
      return _client.IdentifiedClientState.fromPartial(e);
    })) || [];
    message.clientsConsensus = ((_object$clientsConsen = object.clientsConsensus) === null || _object$clientsConsen === void 0 ? void 0 : _object$clientsConsen.map(function (e) {
      return _client.ClientConsensusStates.fromPartial(e);
    })) || [];
    message.clientsMetadata = ((_object$clientsMetada = object.clientsMetadata) === null || _object$clientsMetada === void 0 ? void 0 : _object$clientsMetada.map(function (e) {
      return IdentifiedGenesisMetadata.fromPartial(e);
    })) || [];
    message.params = object.params !== undefined && object.params !== null ? _client.Params.fromPartial(object.params) : undefined;
    message.createLocalhost = (_object$createLocalho = object.createLocalhost) !== null && _object$createLocalho !== void 0 ? _object$createLocalho : false;
    message.nextClientSequence = object.nextClientSequence !== undefined && object.nextClientSequence !== null ? _helpers.Long.fromValue(object.nextClientSequence) : _helpers.Long.UZERO;
    return message;
  }
};
function createBaseGenesisMetadata() {
  return {
    key: new Uint8Array(),
    value: new Uint8Array()
  };
}
var GenesisMetadata = exports.GenesisMetadata = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.key.length !== 0) {
      writer.uint32(10).bytes(message.key);
    }
    if (message.value.length !== 0) {
      writer.uint32(18).bytes(message.value);
    }
    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 = createBaseGenesisMetadata();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.key = reader.bytes();
          break;
        case 2:
          message.value = reader.bytes();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      key: (0, _helpers.isSet)(object.key) ? (0, _helpers.bytesFromBase64)(object.key) : new Uint8Array(),
      value: (0, _helpers.isSet)(object.value) ? (0, _helpers.bytesFromBase64)(object.value) : new Uint8Array()
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.key !== undefined && (obj.key = (0, _helpers.base64FromBytes)(message.key !== undefined ? message.key : new Uint8Array()));
    message.value !== undefined && (obj.value = (0, _helpers.base64FromBytes)(message.value !== undefined ? message.value : new Uint8Array()));
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$key, _object$value;
    var message = createBaseGenesisMetadata();
    message.key = (_object$key = object.key) !== null && _object$key !== void 0 ? _object$key : new Uint8Array();
    message.value = (_object$value = object.value) !== null && _object$value !== void 0 ? _object$value : new Uint8Array();
    return message;
  }
};
function createBaseIdentifiedGenesisMetadata() {
  return {
    clientId: "",
    clientMetadata: []
  };
}
var IdentifiedGenesisMetadata = exports.IdentifiedGenesisMetadata = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.clientId !== "") {
      writer.uint32(10).string(message.clientId);
    }
    var _iterator4 = _createForOfIteratorHelper(message.clientMetadata),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var v = _step4.value;
        GenesisMetadata.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.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 = createBaseIdentifiedGenesisMetadata();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.clientId = reader.string();
          break;
        case 2:
          message.clientMetadata.push(GenesisMetadata.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      clientId: (0, _helpers.isSet)(object.clientId) ? String(object.clientId) : "",
      clientMetadata: Array.isArray(object === null || object === void 0 ? void 0 : object.clientMetadata) ? object.clientMetadata.map(function (e) {
        return GenesisMetadata.fromJSON(e);
      }) : []
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.clientId !== undefined && (obj.clientId = message.clientId);
    if (message.clientMetadata) {
      obj.clientMetadata = message.clientMetadata.map(function (e) {
        return e ? GenesisMetadata.toJSON(e) : undefined;
      });
    } else {
      obj.clientMetadata = [];
    }
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$clientId, _object$clientMetadat;
    var message = createBaseIdentifiedGenesisMetadata();
    message.clientId = (_object$clientId = object.clientId) !== null && _object$clientId !== void 0 ? _object$clientId : "";
    message.clientMetadata = ((_object$clientMetadat = object.clientMetadata) === null || _object$clientMetadat === void 0 ? void 0 : _object$clientMetadat.map(function (e) {
      return GenesisMetadata.fromPartial(e);
    })) || [];
    return message;
  }
};