import { seriesFromJSON } from "./pool";
import { Coin } from "../cosmos/base/v1beta1/coin";
import { BinaryWriter } from "../binary";
import { isSet } from "../helpers";
/** 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: []
  };
}
export const Reward = {
  typeUrl: "/gitopia.gitopia.rewards.Reward",
  encode(message, writer = BinaryWriter.create()) {
    if (message.recipient !== "") {
      writer.uint32(10).string(message.recipient);
    }
    for (const v of message.rewards) {
      RecipientReward.encode(v, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      recipient: isSet(object.recipient) ? String(object.recipient) : "",
      rewards: Array.isArray(object === null || object === void 0 ? void 0 : object.rewards) ? object.rewards.map(e => RecipientReward.fromJSON(e)) : []
    };
  },
  fromPartial(object) {
    var _object$recipient, _object$rewards;
    const 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(e => RecipientReward.fromPartial(e))) || [];
    return message;
  },
  fromAmino(object) {
    var _object$rewards2;
    const 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(e => RecipientReward.fromAmino(e))) || [];
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.recipient = message.recipient === "" ? undefined : message.recipient;
    if (message.rewards) {
      obj.rewards = message.rewards.map(e => e ? RecipientReward.toAmino(e) : undefined);
    } else {
      obj.rewards = message.rewards;
    }
    return obj;
  },
  fromAminoMsg(object) {
    return Reward.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return Reward.decode(message.value);
  },
  toProto(message) {
    return Reward.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.Reward",
      value: Reward.encode(message).finish()
    };
  }
};
function createBaseRecipientReward() {
  return {
    series: 0,
    amount: Coin.fromPartial({}),
    creator: "",
    claimedAmount: Coin.fromPartial({}),
    claimedAmountWithDecay: Coin.fromPartial({})
  };
}
export const RecipientReward = {
  typeUrl: "/gitopia.gitopia.rewards.RecipientReward",
  encode(message, writer = BinaryWriter.create()) {
    if (message.series !== 0) {
      writer.uint32(8).int32(message.series);
    }
    if (message.amount !== undefined) {
      Coin.encode(message.amount, writer.uint32(18).fork()).ldelim();
    }
    if (message.creator !== "") {
      writer.uint32(26).string(message.creator);
    }
    if (message.claimedAmount !== undefined) {
      Coin.encode(message.claimedAmount, writer.uint32(34).fork()).ldelim();
    }
    if (message.claimedAmountWithDecay !== undefined) {
      Coin.encode(message.claimedAmountWithDecay, writer.uint32(42).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      series: isSet(object.series) ? seriesFromJSON(object.series) : -1,
      amount: isSet(object.amount) ? Coin.fromJSON(object.amount) : undefined,
      creator: isSet(object.creator) ? String(object.creator) : "",
      claimedAmount: isSet(object.claimedAmount) ? Coin.fromJSON(object.claimedAmount) : undefined,
      claimedAmountWithDecay: isSet(object.claimedAmountWithDecay) ? Coin.fromJSON(object.claimedAmountWithDecay) : undefined
    };
  },
  fromPartial(object) {
    var _object$series, _object$creator;
    const 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.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.fromPartial(object.claimedAmount) : undefined;
    message.claimedAmountWithDecay = object.claimedAmountWithDecay !== undefined && object.claimedAmountWithDecay !== null ? Coin.fromPartial(object.claimedAmountWithDecay) : undefined;
    return message;
  },
  fromAmino(object) {
    const message = createBaseRecipientReward();
    if (object.series !== undefined && object.series !== null) {
      message.series = object.series;
    }
    if (object.amount !== undefined && object.amount !== null) {
      message.amount = 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.fromAmino(object.claimed_amount);
    }
    if (object.claimed_amount_with_decay !== undefined && object.claimed_amount_with_decay !== null) {
      message.claimedAmountWithDecay = Coin.fromAmino(object.claimed_amount_with_decay);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.series = message.series === 0 ? undefined : message.series;
    obj.amount = message.amount ? Coin.toAmino(message.amount) : undefined;
    obj.creator = message.creator === "" ? undefined : message.creator;
    obj.claimed_amount = message.claimedAmount ? Coin.toAmino(message.claimedAmount) : undefined;
    obj.claimed_amount_with_decay = message.claimedAmountWithDecay ? Coin.toAmino(message.claimedAmountWithDecay) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return RecipientReward.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return RecipientReward.decode(message.value);
  },
  toProto(message) {
    return RecipientReward.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.RecipientReward",
      value: RecipientReward.encode(message).finish()
    };
  }
};