"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Reward = exports.RecipientReward = void 0;
var _pool = require("./pool");
var _coin = require("../cosmos/base/v1beta1/coin");
var _binary = require("../binary");
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; }
/** a map from recipient to all her rewards */

/** a map from recipient to all her rewards */

/** a map from recipient to all her rewards */

function createBaseReward() {
  return {
    recipient: "",
    rewards: []
  };
}
var Reward = exports.Reward = {
  typeUrl: "/gitopia.gitopia.rewards.Reward",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.recipient !== "") {
      writer.uint32(10).string(message.recipient);
    }
    var _iterator = _createForOfIteratorHelper(message.rewards),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        RecipientReward.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      recipient: (0, _helpers.isSet)(object.recipient) ? String(object.recipient) : "",
      rewards: Array.isArray(object === null || object === void 0 ? void 0 : object.rewards) ? object.rewards.map(function (e) {
        return RecipientReward.fromJSON(e);
      }) : []
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$recipient, _object$rewards;
    var message = createBaseReward();
    message.recipient = (_object$recipient = object.recipient) !== null && _object$recipient !== void 0 ? _object$recipient : "";
    message.rewards = ((_object$rewards = object.rewards) === null || _object$rewards === void 0 ? void 0 : _object$rewards.map(function (e) {
      return RecipientReward.fromPartial(e);
    })) || [];
    return message;
  },
  fromAmino: function fromAmino(object) {
    var _object$rewards2;
    var message = createBaseReward();
    if (object.recipient !== undefined && object.recipient !== null) {
      message.recipient = object.recipient;
    }
    message.rewards = ((_object$rewards2 = object.rewards) === null || _object$rewards2 === void 0 ? void 0 : _object$rewards2.map(function (e) {
      return RecipientReward.fromAmino(e);
    })) || [];
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.recipient = message.recipient === "" ? undefined : message.recipient;
    if (message.rewards) {
      obj.rewards = message.rewards.map(function (e) {
        return e ? RecipientReward.toAmino(e) : undefined;
      });
    } else {
      obj.rewards = message.rewards;
    }
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return Reward.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return Reward.decode(message.value);
  },
  toProto: function toProto(message) {
    return Reward.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.Reward",
      value: Reward.encode(message).finish()
    };
  }
};
function createBaseRecipientReward() {
  return {
    series: 0,
    amount: _coin.Coin.fromPartial({}),
    creator: "",
    claimedAmount: _coin.Coin.fromPartial({}),
    claimedAmountWithDecay: _coin.Coin.fromPartial({})
  };
}
var RecipientReward = exports.RecipientReward = {
  typeUrl: "/gitopia.gitopia.rewards.RecipientReward",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.series !== 0) {
      writer.uint32(8).int32(message.series);
    }
    if (message.amount !== undefined) {
      _coin.Coin.encode(message.amount, writer.uint32(18).fork()).ldelim();
    }
    if (message.creator !== "") {
      writer.uint32(26).string(message.creator);
    }
    if (message.claimedAmount !== undefined) {
      _coin.Coin.encode(message.claimedAmount, writer.uint32(34).fork()).ldelim();
    }
    if (message.claimedAmountWithDecay !== undefined) {
      _coin.Coin.encode(message.claimedAmountWithDecay, writer.uint32(42).fork()).ldelim();
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      series: (0, _helpers.isSet)(object.series) ? (0, _pool.seriesFromJSON)(object.series) : -1,
      amount: (0, _helpers.isSet)(object.amount) ? _coin.Coin.fromJSON(object.amount) : undefined,
      creator: (0, _helpers.isSet)(object.creator) ? String(object.creator) : "",
      claimedAmount: (0, _helpers.isSet)(object.claimedAmount) ? _coin.Coin.fromJSON(object.claimedAmount) : undefined,
      claimedAmountWithDecay: (0, _helpers.isSet)(object.claimedAmountWithDecay) ? _coin.Coin.fromJSON(object.claimedAmountWithDecay) : undefined
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$series, _object$creator;
    var message = createBaseRecipientReward();
    message.series = (_object$series = object.series) !== null && _object$series !== void 0 ? _object$series : 0;
    message.amount = object.amount !== undefined && object.amount !== null ? _coin.Coin.fromPartial(object.amount) : undefined;
    message.creator = (_object$creator = object.creator) !== null && _object$creator !== void 0 ? _object$creator : "";
    message.claimedAmount = object.claimedAmount !== undefined && object.claimedAmount !== null ? _coin.Coin.fromPartial(object.claimedAmount) : undefined;
    message.claimedAmountWithDecay = object.claimedAmountWithDecay !== undefined && object.claimedAmountWithDecay !== null ? _coin.Coin.fromPartial(object.claimedAmountWithDecay) : undefined;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseRecipientReward();
    if (object.series !== undefined && object.series !== null) {
      message.series = object.series;
    }
    if (object.amount !== undefined && object.amount !== null) {
      message.amount = _coin.Coin.fromAmino(object.amount);
    }
    if (object.creator !== undefined && object.creator !== null) {
      message.creator = object.creator;
    }
    if (object.claimed_amount !== undefined && object.claimed_amount !== null) {
      message.claimedAmount = _coin.Coin.fromAmino(object.claimed_amount);
    }
    if (object.claimed_amount_with_decay !== undefined && object.claimed_amount_with_decay !== null) {
      message.claimedAmountWithDecay = _coin.Coin.fromAmino(object.claimed_amount_with_decay);
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.series = message.series === 0 ? undefined : message.series;
    obj.amount = message.amount ? _coin.Coin.toAmino(message.amount) : undefined;
    obj.creator = message.creator === "" ? undefined : message.creator;
    obj.claimed_amount = message.claimedAmount ? _coin.Coin.toAmino(message.claimedAmount) : undefined;
    obj.claimed_amount_with_decay = message.claimedAmountWithDecay ? _coin.Coin.toAmino(message.claimedAmountWithDecay) : undefined;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return RecipientReward.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return RecipientReward.decode(message.value);
  },
  toProto: function toProto(message) {
    return RecipientReward.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.RecipientReward",
      value: RecipientReward.encode(message).finish()
    };
  }
};