import { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination";
import { Params } from "./params";
import { Task } from "./task";
import { seriesFromJSON } from "./pool";
import { Coin } from "../cosmos/base/v1beta1/coin";
import { Reward } from "./rewards";
import { BinaryWriter } from "../binary";
import { isSet } from "../helpers";
/** QueryParamsRequest is the request type for the Query/Params RPC method. */

/** QueryParamsRequest is the request type for the Query/Params RPC method. */

/** QueryParamsRequest is the request type for the Query/Params RPC method. */

/** QueryParamsResponse is the response type for the Query/Params RPC method. */

/** QueryParamsResponse is the response type for the Query/Params RPC method. */

/** QueryParamsResponse is the response type for the Query/Params RPC method. */

function createBaseQueryParamsRequest() {
  return {};
}
export const QueryParamsRequest = {
  typeUrl: "/gitopia.gitopia.rewards.QueryParamsRequest",
  encode(_, writer = BinaryWriter.create()) {
    return writer;
  },
  fromJSON(_) {
    return {};
  },
  fromPartial(_) {
    const message = createBaseQueryParamsRequest();
    return message;
  },
  fromAmino(_) {
    const message = createBaseQueryParamsRequest();
    return message;
  },
  toAmino(_) {
    const obj = {};
    return obj;
  },
  fromAminoMsg(object) {
    return QueryParamsRequest.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryParamsRequest.decode(message.value);
  },
  toProto(message) {
    return QueryParamsRequest.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryParamsRequest",
      value: QueryParamsRequest.encode(message).finish()
    };
  }
};
function createBaseQueryParamsResponse() {
  return {
    params: Params.fromPartial({})
  };
}
export const QueryParamsResponse = {
  typeUrl: "/gitopia.gitopia.rewards.QueryParamsResponse",
  encode(message, writer = BinaryWriter.create()) {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      params: isSet(object.params) ? Params.fromJSON(object.params) : undefined
    };
  },
  fromPartial(object) {
    const message = createBaseQueryParamsResponse();
    message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
    return message;
  },
  fromAmino(object) {
    const message = createBaseQueryParamsResponse();
    if (object.params !== undefined && object.params !== null) {
      message.params = Params.fromAmino(object.params);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.params = message.params ? Params.toAmino(message.params) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return QueryParamsResponse.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryParamsResponse.decode(message.value);
  },
  toProto(message) {
    return QueryParamsResponse.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryParamsResponse",
      value: QueryParamsResponse.encode(message).finish()
    };
  }
};
function createBaseQueryTasksRequest() {
  return {
    address: ""
  };
}
export const QueryTasksRequest = {
  typeUrl: "/gitopia.gitopia.rewards.QueryTasksRequest",
  encode(message, writer = BinaryWriter.create()) {
    if (message.address !== "") {
      writer.uint32(10).string(message.address);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      address: isSet(object.address) ? String(object.address) : ""
    };
  },
  fromPartial(object) {
    var _object$address;
    const message = createBaseQueryTasksRequest();
    message.address = (_object$address = object.address) !== null && _object$address !== void 0 ? _object$address : "";
    return message;
  },
  fromAmino(object) {
    const message = createBaseQueryTasksRequest();
    if (object.address !== undefined && object.address !== null) {
      message.address = object.address;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.address = message.address === "" ? undefined : message.address;
    return obj;
  },
  fromAminoMsg(object) {
    return QueryTasksRequest.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryTasksRequest.decode(message.value);
  },
  toProto(message) {
    return QueryTasksRequest.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryTasksRequest",
      value: QueryTasksRequest.encode(message).finish()
    };
  }
};
function createBaseQueryTasksResponse() {
  return {
    tasks: []
  };
}
export const QueryTasksResponse = {
  typeUrl: "/gitopia.gitopia.rewards.QueryTasksResponse",
  encode(message, writer = BinaryWriter.create()) {
    for (const v of message.tasks) {
      Task.encode(v, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      tasks: Array.isArray(object === null || object === void 0 ? void 0 : object.tasks) ? object.tasks.map(e => Task.fromJSON(e)) : []
    };
  },
  fromPartial(object) {
    var _object$tasks;
    const message = createBaseQueryTasksResponse();
    message.tasks = ((_object$tasks = object.tasks) === null || _object$tasks === void 0 ? void 0 : _object$tasks.map(e => Task.fromPartial(e))) || [];
    return message;
  },
  fromAmino(object) {
    var _object$tasks2;
    const message = createBaseQueryTasksResponse();
    message.tasks = ((_object$tasks2 = object.tasks) === null || _object$tasks2 === void 0 ? void 0 : _object$tasks2.map(e => Task.fromAmino(e))) || [];
    return message;
  },
  toAmino(message) {
    const obj = {};
    if (message.tasks) {
      obj.tasks = message.tasks.map(e => e ? Task.toAmino(e) : undefined);
    } else {
      obj.tasks = message.tasks;
    }
    return obj;
  },
  fromAminoMsg(object) {
    return QueryTasksResponse.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryTasksResponse.decode(message.value);
  },
  toProto(message) {
    return QueryTasksResponse.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryTasksResponse",
      value: QueryTasksResponse.encode(message).finish()
    };
  }
};
function createBaseQueryGetRewardRequest() {
  return {
    recipient: ""
  };
}
export const QueryGetRewardRequest = {
  typeUrl: "/gitopia.gitopia.rewards.QueryGetRewardRequest",
  encode(message, writer = BinaryWriter.create()) {
    if (message.recipient !== "") {
      writer.uint32(10).string(message.recipient);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      recipient: isSet(object.recipient) ? String(object.recipient) : ""
    };
  },
  fromPartial(object) {
    var _object$recipient;
    const message = createBaseQueryGetRewardRequest();
    message.recipient = (_object$recipient = object.recipient) !== null && _object$recipient !== void 0 ? _object$recipient : "";
    return message;
  },
  fromAmino(object) {
    const message = createBaseQueryGetRewardRequest();
    if (object.recipient !== undefined && object.recipient !== null) {
      message.recipient = object.recipient;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.recipient = message.recipient === "" ? undefined : message.recipient;
    return obj;
  },
  fromAminoMsg(object) {
    return QueryGetRewardRequest.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryGetRewardRequest.decode(message.value);
  },
  toProto(message) {
    return QueryGetRewardRequest.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryGetRewardRequest",
      value: QueryGetRewardRequest.encode(message).finish()
    };
  }
};
function createBaseQueryGetRewardResponseReward() {
  return {
    creator: "",
    series: 0,
    amount: Coin.fromPartial({}),
    claimedAmount: Coin.fromPartial({}),
    claimableAmount: Coin.fromPartial({}),
    remainingClaimableAmount: Coin.fromPartial({})
  };
}
export const QueryGetRewardResponseReward = {
  typeUrl: "/gitopia.gitopia.rewards.QueryGetRewardResponseReward",
  encode(message, writer = BinaryWriter.create()) {
    if (message.creator !== "") {
      writer.uint32(10).string(message.creator);
    }
    if (message.series !== 0) {
      writer.uint32(16).int32(message.series);
    }
    if (message.amount !== undefined) {
      Coin.encode(message.amount, writer.uint32(26).fork()).ldelim();
    }
    if (message.claimedAmount !== undefined) {
      Coin.encode(message.claimedAmount, writer.uint32(34).fork()).ldelim();
    }
    if (message.claimableAmount !== undefined) {
      Coin.encode(message.claimableAmount, writer.uint32(42).fork()).ldelim();
    }
    if (message.remainingClaimableAmount !== undefined) {
      Coin.encode(message.remainingClaimableAmount, writer.uint32(50).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      creator: isSet(object.creator) ? String(object.creator) : "",
      series: isSet(object.series) ? seriesFromJSON(object.series) : -1,
      amount: isSet(object.amount) ? Coin.fromJSON(object.amount) : undefined,
      claimedAmount: isSet(object.claimedAmount) ? Coin.fromJSON(object.claimedAmount) : undefined,
      claimableAmount: isSet(object.claimableAmount) ? Coin.fromJSON(object.claimableAmount) : undefined,
      remainingClaimableAmount: isSet(object.remainingClaimableAmount) ? Coin.fromJSON(object.remainingClaimableAmount) : undefined
    };
  },
  fromPartial(object) {
    var _object$creator, _object$series;
    const message = createBaseQueryGetRewardResponseReward();
    message.creator = (_object$creator = object.creator) !== null && _object$creator !== void 0 ? _object$creator : "";
    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.claimedAmount = object.claimedAmount !== undefined && object.claimedAmount !== null ? Coin.fromPartial(object.claimedAmount) : undefined;
    message.claimableAmount = object.claimableAmount !== undefined && object.claimableAmount !== null ? Coin.fromPartial(object.claimableAmount) : undefined;
    message.remainingClaimableAmount = object.remainingClaimableAmount !== undefined && object.remainingClaimableAmount !== null ? Coin.fromPartial(object.remainingClaimableAmount) : undefined;
    return message;
  },
  fromAmino(object) {
    const message = createBaseQueryGetRewardResponseReward();
    if (object.creator !== undefined && object.creator !== null) {
      message.creator = object.creator;
    }
    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.claimed_amount !== undefined && object.claimed_amount !== null) {
      message.claimedAmount = Coin.fromAmino(object.claimed_amount);
    }
    if (object.claimable_amount !== undefined && object.claimable_amount !== null) {
      message.claimableAmount = Coin.fromAmino(object.claimable_amount);
    }
    if (object.remaining_claimable_amount !== undefined && object.remaining_claimable_amount !== null) {
      message.remainingClaimableAmount = Coin.fromAmino(object.remaining_claimable_amount);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.creator = message.creator === "" ? undefined : message.creator;
    obj.series = message.series === 0 ? undefined : message.series;
    obj.amount = message.amount ? Coin.toAmino(message.amount) : undefined;
    obj.claimed_amount = message.claimedAmount ? Coin.toAmino(message.claimedAmount) : undefined;
    obj.claimable_amount = message.claimableAmount ? Coin.toAmino(message.claimableAmount) : undefined;
    obj.remaining_claimable_amount = message.remainingClaimableAmount ? Coin.toAmino(message.remainingClaimableAmount) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return QueryGetRewardResponseReward.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryGetRewardResponseReward.decode(message.value);
  },
  toProto(message) {
    return QueryGetRewardResponseReward.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryGetRewardResponseReward",
      value: QueryGetRewardResponseReward.encode(message).finish()
    };
  }
};
function createBaseQueryGetRewardResponse() {
  return {
    recipient: "",
    rewards: []
  };
}
export const QueryGetRewardResponse = {
  typeUrl: "/gitopia.gitopia.rewards.QueryGetRewardResponse",
  encode(message, writer = BinaryWriter.create()) {
    if (message.recipient !== "") {
      writer.uint32(10).string(message.recipient);
    }
    for (const v of message.rewards) {
      QueryGetRewardResponseReward.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 => QueryGetRewardResponseReward.fromJSON(e)) : []
    };
  },
  fromPartial(object) {
    var _object$recipient2, _object$rewards;
    const message = createBaseQueryGetRewardResponse();
    message.recipient = (_object$recipient2 = object.recipient) !== null && _object$recipient2 !== void 0 ? _object$recipient2 : "";
    message.rewards = ((_object$rewards = object.rewards) === null || _object$rewards === void 0 ? void 0 : _object$rewards.map(e => QueryGetRewardResponseReward.fromPartial(e))) || [];
    return message;
  },
  fromAmino(object) {
    var _object$rewards2;
    const message = createBaseQueryGetRewardResponse();
    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 => QueryGetRewardResponseReward.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 ? QueryGetRewardResponseReward.toAmino(e) : undefined);
    } else {
      obj.rewards = message.rewards;
    }
    return obj;
  },
  fromAminoMsg(object) {
    return QueryGetRewardResponse.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryGetRewardResponse.decode(message.value);
  },
  toProto(message) {
    return QueryGetRewardResponse.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryGetRewardResponse",
      value: QueryGetRewardResponse.encode(message).finish()
    };
  }
};
function createBaseQueryAllRewardsRequest() {
  return {
    pagination: undefined
  };
}
export const QueryAllRewardsRequest = {
  typeUrl: "/gitopia.gitopia.rewards.QueryAllRewardsRequest",
  encode(message, writer = BinaryWriter.create()) {
    if (message.pagination !== undefined) {
      PageRequest.encode(message.pagination, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined
    };
  },
  fromPartial(object) {
    const message = createBaseQueryAllRewardsRequest();
    message.pagination = object.pagination !== undefined && object.pagination !== null ? PageRequest.fromPartial(object.pagination) : undefined;
    return message;
  },
  fromAmino(object) {
    const message = createBaseQueryAllRewardsRequest();
    if (object.pagination !== undefined && object.pagination !== null) {
      message.pagination = PageRequest.fromAmino(object.pagination);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.pagination = message.pagination ? PageRequest.toAmino(message.pagination) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return QueryAllRewardsRequest.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryAllRewardsRequest.decode(message.value);
  },
  toProto(message) {
    return QueryAllRewardsRequest.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryAllRewardsRequest",
      value: QueryAllRewardsRequest.encode(message).finish()
    };
  }
};
function createBaseQueryAllRewardsResponse() {
  return {
    rewards: [],
    pagination: undefined
  };
}
export const QueryAllRewardsResponse = {
  typeUrl: "/gitopia.gitopia.rewards.QueryAllRewardsResponse",
  encode(message, writer = BinaryWriter.create()) {
    for (const v of message.rewards) {
      Reward.encode(v, writer.uint32(10).fork()).ldelim();
    }
    if (message.pagination !== undefined) {
      PageResponse.encode(message.pagination, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      rewards: Array.isArray(object === null || object === void 0 ? void 0 : object.rewards) ? object.rewards.map(e => Reward.fromJSON(e)) : [],
      pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined
    };
  },
  fromPartial(object) {
    var _object$rewards3;
    const message = createBaseQueryAllRewardsResponse();
    message.rewards = ((_object$rewards3 = object.rewards) === null || _object$rewards3 === void 0 ? void 0 : _object$rewards3.map(e => Reward.fromPartial(e))) || [];
    message.pagination = object.pagination !== undefined && object.pagination !== null ? PageResponse.fromPartial(object.pagination) : undefined;
    return message;
  },
  fromAmino(object) {
    var _object$rewards4;
    const message = createBaseQueryAllRewardsResponse();
    message.rewards = ((_object$rewards4 = object.rewards) === null || _object$rewards4 === void 0 ? void 0 : _object$rewards4.map(e => Reward.fromAmino(e))) || [];
    if (object.pagination !== undefined && object.pagination !== null) {
      message.pagination = PageResponse.fromAmino(object.pagination);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    if (message.rewards) {
      obj.rewards = message.rewards.map(e => e ? Reward.toAmino(e) : undefined);
    } else {
      obj.rewards = message.rewards;
    }
    obj.pagination = message.pagination ? PageResponse.toAmino(message.pagination) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return QueryAllRewardsResponse.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return QueryAllRewardsResponse.decode(message.value);
  },
  toProto(message) {
    return QueryAllRewardsResponse.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.rewards.QueryAllRewardsResponse",
      value: QueryAllRewardsResponse.encode(message).finish()
    };
  }
};