import { Params, InsuranceFund, RedemptionSchedule } from "./insurance";
import { Long } from "../../../helpers";
import * as _m0 from "protobufjs/minimal";
/** GenesisState defines the insurance module's genesis state. */

function createBaseGenesisState() {
  return {
    params: undefined,
    insuranceFunds: [],
    redemptionSchedule: [],
    nextShareDenomId: Long.UZERO,
    nextRedemptionScheduleId: Long.UZERO
  };
}
export const GenesisState = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    for (const v of message.insuranceFunds) {
      InsuranceFund.encode(v, writer.uint32(18).fork()).ldelim();
    }
    for (const v of message.redemptionSchedule) {
      RedemptionSchedule.encode(v, writer.uint32(26).fork()).ldelim();
    }
    if (!message.nextShareDenomId.isZero()) {
      writer.uint32(32).uint64(message.nextShareDenomId);
    }
    if (!message.nextRedemptionScheduleId.isZero()) {
      writer.uint32(40).uint64(message.nextRedemptionScheduleId);
    }
    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 = createBaseGenesisState();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.insuranceFunds.push(InsuranceFund.decode(reader, reader.uint32()));
          break;
        case 3:
          message.redemptionSchedule.push(RedemptionSchedule.decode(reader, reader.uint32()));
          break;
        case 4:
          message.nextShareDenomId = reader.uint64();
          break;
        case 5:
          message.nextRedemptionScheduleId = reader.uint64();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$insuranceFund, _object$redemptionSch;
    const message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
    message.insuranceFunds = ((_object$insuranceFund = object.insuranceFunds) === null || _object$insuranceFund === void 0 ? void 0 : _object$insuranceFund.map(e => InsuranceFund.fromPartial(e))) || [];
    message.redemptionSchedule = ((_object$redemptionSch = object.redemptionSchedule) === null || _object$redemptionSch === void 0 ? void 0 : _object$redemptionSch.map(e => RedemptionSchedule.fromPartial(e))) || [];
    message.nextShareDenomId = object.nextShareDenomId !== undefined && object.nextShareDenomId !== null ? Long.fromValue(object.nextShareDenomId) : Long.UZERO;
    message.nextRedemptionScheduleId = object.nextRedemptionScheduleId !== undefined && object.nextRedemptionScheduleId !== null ? Long.fromValue(object.nextRedemptionScheduleId) : Long.UZERO;
    return message;
  }
};