/* eslint-disable */
import { Params } from "../cosmostest/params";
import { NextAuction } from "../cosmostest/next_auction";
import { Auction } from "../cosmostest/auction";
import { Writer, Reader } from "protobufjs/minimal";

export const protobufPackage = "cosmostest.cosmostest";

/** GenesisState defines the cosmostest module's genesis state. */
export interface GenesisState {
  params: Params | undefined;
  nextAuction: NextAuction | undefined;
  /** this line is used by starport scaffolding # genesis/proto/state */
  auctionList: Auction[];
}

const baseGenesisState: object = {};

export const GenesisState = {
  encode(message: GenesisState, writer: Writer = Writer.create()): Writer {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    if (message.nextAuction !== undefined) {
      NextAuction.encode(
        message.nextAuction,
        writer.uint32(18).fork()
      ).ldelim();
    }
    for (const v of message.auctionList) {
      Auction.encode(v!, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },

  decode(input: Reader | Uint8Array, length?: number): GenesisState {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = { ...baseGenesisState } as GenesisState;
    message.auctionList = [];
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.nextAuction = NextAuction.decode(reader, reader.uint32());
          break;
        case 3:
          message.auctionList.push(Auction.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(object: any): GenesisState {
    const message = { ...baseGenesisState } as GenesisState;
    message.auctionList = [];
    if (object.params !== undefined && object.params !== null) {
      message.params = Params.fromJSON(object.params);
    } else {
      message.params = undefined;
    }
    if (object.nextAuction !== undefined && object.nextAuction !== null) {
      message.nextAuction = NextAuction.fromJSON(object.nextAuction);
    } else {
      message.nextAuction = undefined;
    }
    if (object.auctionList !== undefined && object.auctionList !== null) {
      for (const e of object.auctionList) {
        message.auctionList.push(Auction.fromJSON(e));
      }
    }
    return message;
  },

  toJSON(message: GenesisState): unknown {
    const obj: any = {};
    message.params !== undefined &&
      (obj.params = message.params ? Params.toJSON(message.params) : undefined);
    message.nextAuction !== undefined &&
      (obj.nextAuction = message.nextAuction
        ? NextAuction.toJSON(message.nextAuction)
        : undefined);
    if (message.auctionList) {
      obj.auctionList = message.auctionList.map((e) =>
        e ? Auction.toJSON(e) : undefined
      );
    } else {
      obj.auctionList = [];
    }
    return obj;
  },

  fromPartial(object: DeepPartial<GenesisState>): GenesisState {
    const message = { ...baseGenesisState } as GenesisState;
    message.auctionList = [];
    if (object.params !== undefined && object.params !== null) {
      message.params = Params.fromPartial(object.params);
    } else {
      message.params = undefined;
    }
    if (object.nextAuction !== undefined && object.nextAuction !== null) {
      message.nextAuction = NextAuction.fromPartial(object.nextAuction);
    } else {
      message.nextAuction = undefined;
    }
    if (object.auctionList !== undefined && object.auctionList !== null) {
      for (const e of object.auctionList) {
        message.auctionList.push(Auction.fromPartial(e));
      }
    }
    return message;
  },
};

type Builtin = Date | Function | Uint8Array | string | number | undefined;
export type DeepPartial<T> = T extends Builtin
  ? T
  : T extends Array<infer U>
  ? Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U>
  ? ReadonlyArray<DeepPartial<U>>
  : T extends {}
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;
