import { Timestamp } from "../../../google/protobuf/timestamp";
import { Coin } from "../../../cosmos/base/v1beta1/coin";
import { Long, toTimestamp, fromTimestamp } from "../../../helpers";
import * as _m0 from "protobufjs/minimal";
/** Schedule defines the parameters of an incentives releasing schedule */

function createBaseSchedule() {
  return {
    id: Long.UZERO,
    startTime: undefined,
    endTime: undefined,
    totalAmount: [],
    releasedAmount: []
  };
}
export const Schedule = {
  encode(message, writer = _m0.Writer.create()) {
    if (!message.id.isZero()) {
      writer.uint32(8).uint64(message.id);
    }
    if (message.startTime !== undefined) {
      Timestamp.encode(toTimestamp(message.startTime), writer.uint32(18).fork()).ldelim();
    }
    if (message.endTime !== undefined) {
      Timestamp.encode(toTimestamp(message.endTime), writer.uint32(26).fork()).ldelim();
    }
    for (const v of message.totalAmount) {
      Coin.encode(v, writer.uint32(34).fork()).ldelim();
    }
    for (const v of message.releasedAmount) {
      Coin.encode(v, writer.uint32(42).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseSchedule();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.id = reader.uint64();
          break;
        case 2:
          message.startTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          break;
        case 3:
          message.endTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          break;
        case 4:
          message.totalAmount.push(Coin.decode(reader, reader.uint32()));
          break;
        case 5:
          message.releasedAmount.push(Coin.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$startTime, _object$endTime, _object$totalAmount, _object$releasedAmoun;
    const message = createBaseSchedule();
    message.id = object.id !== undefined && object.id !== null ? Long.fromValue(object.id) : Long.UZERO;
    message.startTime = (_object$startTime = object.startTime) !== null && _object$startTime !== void 0 ? _object$startTime : undefined;
    message.endTime = (_object$endTime = object.endTime) !== null && _object$endTime !== void 0 ? _object$endTime : undefined;
    message.totalAmount = ((_object$totalAmount = object.totalAmount) === null || _object$totalAmount === void 0 ? void 0 : _object$totalAmount.map(e => Coin.fromPartial(e))) || [];
    message.releasedAmount = ((_object$releasedAmoun = object.releasedAmount) === null || _object$releasedAmoun === void 0 ? void 0 : _object$releasedAmoun.map(e => Coin.fromPartial(e))) || [];
    return message;
  }
};