"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PoolProportions = exports.Params = exports.DistributionProportion = void 0;
var _timestamp = require("../google/protobuf/timestamp");
var _binary = require("../binary");
var _math = require("@cosmjs/math");
var _helpers = require("../helpers");
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/** Params defines the parameters for the module. */

/** Params defines the parameters for the module. */

/** Params defines the parameters for the module. */

function createBaseDistributionProportion() {
  return {
    proportion: "",
    address: ""
  };
}
var DistributionProportion = exports.DistributionProportion = {
  typeUrl: "/gitopia.gitopia.gitopia.DistributionProportion",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.proportion !== "") {
      writer.uint32(10).string(_math.Decimal.fromUserInput(message.proportion, 18).atomics);
    }
    if (message.address !== "") {
      writer.uint32(18).string(message.address);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      proportion: (0, _helpers.isSet)(object.proportion) ? String(object.proportion) : "",
      address: (0, _helpers.isSet)(object.address) ? String(object.address) : ""
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$proportion, _object$address;
    var message = createBaseDistributionProportion();
    message.proportion = (_object$proportion = object.proportion) !== null && _object$proportion !== void 0 ? _object$proportion : "";
    message.address = (_object$address = object.address) !== null && _object$address !== void 0 ? _object$address : "";
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseDistributionProportion();
    if (object.proportion !== undefined && object.proportion !== null) {
      message.proportion = object.proportion;
    }
    if (object.address !== undefined && object.address !== null) {
      message.address = object.address;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.proportion = message.proportion === "" ? undefined : message.proportion;
    obj.address = message.address === "" ? undefined : message.address;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return DistributionProportion.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return DistributionProportion.decode(message.value);
  },
  toProto: function toProto(message) {
    return DistributionProportion.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.DistributionProportion",
      value: DistributionProportion.encode(message).finish()
    };
  }
};
function createBasePoolProportions() {
  return {
    ecosystem: undefined,
    team: undefined,
    platform: undefined
  };
}
var PoolProportions = exports.PoolProportions = {
  typeUrl: "/gitopia.gitopia.gitopia.PoolProportions",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.ecosystem !== undefined) {
      DistributionProportion.encode(message.ecosystem, writer.uint32(10).fork()).ldelim();
    }
    if (message.team !== undefined) {
      DistributionProportion.encode(message.team, writer.uint32(18).fork()).ldelim();
    }
    if (message.platform !== undefined) {
      DistributionProportion.encode(message.platform, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      ecosystem: (0, _helpers.isSet)(object.ecosystem) ? DistributionProportion.fromJSON(object.ecosystem) : undefined,
      team: (0, _helpers.isSet)(object.team) ? DistributionProportion.fromJSON(object.team) : undefined,
      platform: (0, _helpers.isSet)(object.platform) ? DistributionProportion.fromJSON(object.platform) : undefined
    };
  },
  fromPartial: function fromPartial(object) {
    var message = createBasePoolProportions();
    message.ecosystem = object.ecosystem !== undefined && object.ecosystem !== null ? DistributionProportion.fromPartial(object.ecosystem) : undefined;
    message.team = object.team !== undefined && object.team !== null ? DistributionProportion.fromPartial(object.team) : undefined;
    message.platform = object.platform !== undefined && object.platform !== null ? DistributionProportion.fromPartial(object.platform) : undefined;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBasePoolProportions();
    if (object.ecosystem !== undefined && object.ecosystem !== null) {
      message.ecosystem = DistributionProportion.fromAmino(object.ecosystem);
    }
    if (object.team !== undefined && object.team !== null) {
      message.team = DistributionProportion.fromAmino(object.team);
    }
    if (object.platform !== undefined && object.platform !== null) {
      message.platform = DistributionProportion.fromAmino(object.platform);
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.ecosystem = message.ecosystem ? DistributionProportion.toAmino(message.ecosystem) : undefined;
    obj.team = message.team ? DistributionProportion.toAmino(message.team) : undefined;
    obj.platform = message.platform ? DistributionProportion.toAmino(message.platform) : undefined;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return PoolProportions.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return PoolProportions.decode(message.value);
  },
  toProto: function toProto(message) {
    return PoolProportions.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.PoolProportions",
      value: PoolProportions.encode(message).finish()
    };
  }
};
function createBaseParams() {
  return {
    nextInflationTime: _timestamp.Timestamp.fromPartial({}),
    poolProportions: PoolProportions.fromPartial({}),
    teamProportions: [],
    genesisTime: _timestamp.Timestamp.fromPartial({}),
    gitServer: "",
    storageProvider: ""
  };
}
var Params = exports.Params = {
  typeUrl: "/gitopia.gitopia.gitopia.Params",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.nextInflationTime !== undefined) {
      _timestamp.Timestamp.encode(message.nextInflationTime, writer.uint32(10).fork()).ldelim();
    }
    if (message.poolProportions !== undefined) {
      PoolProportions.encode(message.poolProportions, writer.uint32(18).fork()).ldelim();
    }
    var _iterator = _createForOfIteratorHelper(message.teamProportions),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        DistributionProportion.encode(v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    if (message.genesisTime !== undefined) {
      _timestamp.Timestamp.encode(message.genesisTime, writer.uint32(34).fork()).ldelim();
    }
    if (message.gitServer !== "") {
      writer.uint32(42).string(message.gitServer);
    }
    if (message.storageProvider !== "") {
      writer.uint32(50).string(message.storageProvider);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      nextInflationTime: (0, _helpers.isSet)(object.nextInflationTime) ? (0, _helpers.fromJsonTimestamp)(object.nextInflationTime) : undefined,
      poolProportions: (0, _helpers.isSet)(object.poolProportions) ? PoolProportions.fromJSON(object.poolProportions) : undefined,
      teamProportions: Array.isArray(object === null || object === void 0 ? void 0 : object.teamProportions) ? object.teamProportions.map(function (e) {
        return DistributionProportion.fromJSON(e);
      }) : [],
      genesisTime: (0, _helpers.isSet)(object.genesisTime) ? (0, _helpers.fromJsonTimestamp)(object.genesisTime) : undefined,
      gitServer: (0, _helpers.isSet)(object.gitServer) ? String(object.gitServer) : "",
      storageProvider: (0, _helpers.isSet)(object.storageProvider) ? String(object.storageProvider) : ""
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$teamProportio, _object$gitServer, _object$storageProvid;
    var message = createBaseParams();
    message.nextInflationTime = object.nextInflationTime !== undefined && object.nextInflationTime !== null ? _timestamp.Timestamp.fromPartial(object.nextInflationTime) : undefined;
    message.poolProportions = object.poolProportions !== undefined && object.poolProportions !== null ? PoolProportions.fromPartial(object.poolProportions) : undefined;
    message.teamProportions = ((_object$teamProportio = object.teamProportions) === null || _object$teamProportio === void 0 ? void 0 : _object$teamProportio.map(function (e) {
      return DistributionProportion.fromPartial(e);
    })) || [];
    message.genesisTime = object.genesisTime !== undefined && object.genesisTime !== null ? _timestamp.Timestamp.fromPartial(object.genesisTime) : undefined;
    message.gitServer = (_object$gitServer = object.gitServer) !== null && _object$gitServer !== void 0 ? _object$gitServer : "";
    message.storageProvider = (_object$storageProvid = object.storageProvider) !== null && _object$storageProvid !== void 0 ? _object$storageProvid : "";
    return message;
  },
  fromAmino: function fromAmino(object) {
    var _object$team_proporti;
    var message = createBaseParams();
    if (object.next_inflation_time !== undefined && object.next_inflation_time !== null) {
      message.nextInflationTime = _timestamp.Timestamp.fromAmino(object.next_inflation_time);
    }
    if (object.pool_proportions !== undefined && object.pool_proportions !== null) {
      message.poolProportions = PoolProportions.fromAmino(object.pool_proportions);
    }
    message.teamProportions = ((_object$team_proporti = object.team_proportions) === null || _object$team_proporti === void 0 ? void 0 : _object$team_proporti.map(function (e) {
      return DistributionProportion.fromAmino(e);
    })) || [];
    if (object.genesis_time !== undefined && object.genesis_time !== null) {
      message.genesisTime = _timestamp.Timestamp.fromAmino(object.genesis_time);
    }
    if (object.git_server !== undefined && object.git_server !== null) {
      message.gitServer = object.git_server;
    }
    if (object.storage_provider !== undefined && object.storage_provider !== null) {
      message.storageProvider = object.storage_provider;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.next_inflation_time = message.nextInflationTime ? _timestamp.Timestamp.toAmino(message.nextInflationTime) : undefined;
    obj.pool_proportions = message.poolProportions ? PoolProportions.toAmino(message.poolProportions) : undefined;
    if (message.teamProportions) {
      obj.team_proportions = message.teamProportions.map(function (e) {
        return e ? DistributionProportion.toAmino(e) : undefined;
      });
    } else {
      obj.team_proportions = message.teamProportions;
    }
    obj.genesis_time = message.genesisTime ? _timestamp.Timestamp.toAmino(message.genesisTime) : undefined;
    obj.git_server = message.gitServer === "" ? undefined : message.gitServer;
    obj.storage_provider = message.storageProvider === "" ? undefined : message.storageProvider;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return Params.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return Params.decode(message.value);
  },
  toProto: function toProto(message) {
    return Params.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.Params",
      value: Params.encode(message).finish()
    };
  }
};