/* eslint-disable */
import { Reader, Writer } from "protobufjs/minimal";
import { Params } from "../cosmostest/params";
import { NextAuction } from "../cosmostest/next_auction";
import { Auction } from "../cosmostest/auction";
import {
  PageRequest,
  PageResponse,
} from "../cosmos/base/query/v1beta1/pagination";

export const protobufPackage = "cosmostest.cosmostest";

/** QueryParamsRequest is request type for the Query/Params RPC method. */
export interface QueryParamsRequest {}

/** QueryParamsResponse is response type for the Query/Params RPC method. */
export interface QueryParamsResponse {
  /** params holds all the parameters of this module. */
  params: Params | undefined;
}

export interface QueryGetNextAuctionRequest {}

export interface QueryGetNextAuctionResponse {
  NextAuction: NextAuction | undefined;
}

export interface QueryGetAuctionRequest {
  index: string;
}

export interface QueryGetAuctionResponse {
  auction: Auction | undefined;
}

export interface QueryAllAuctionRequest {
  pagination: PageRequest | undefined;
}

export interface QueryAllAuctionResponse {
  auction: Auction[];
  pagination: PageResponse | undefined;
}

const baseQueryParamsRequest: object = {};

export const QueryParamsRequest = {
  encode(_: QueryParamsRequest, writer: Writer = Writer.create()): Writer {
    return writer;
  },

  decode(input: Reader | Uint8Array, length?: number): QueryParamsRequest {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = { ...baseQueryParamsRequest } as QueryParamsRequest;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(_: any): QueryParamsRequest {
    const message = { ...baseQueryParamsRequest } as QueryParamsRequest;
    return message;
  },

  toJSON(_: QueryParamsRequest): unknown {
    const obj: any = {};
    return obj;
  },

  fromPartial(_: DeepPartial<QueryParamsRequest>): QueryParamsRequest {
    const message = { ...baseQueryParamsRequest } as QueryParamsRequest;
    return message;
  },
};

const baseQueryParamsResponse: object = {};

export const QueryParamsResponse = {
  encode(
    message: QueryParamsResponse,
    writer: Writer = Writer.create()
  ): Writer {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: Reader | Uint8Array, length?: number): QueryParamsResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = { ...baseQueryParamsResponse } as QueryParamsResponse;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = Params.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(object: any): QueryParamsResponse {
    const message = { ...baseQueryParamsResponse } as QueryParamsResponse;
    if (object.params !== undefined && object.params !== null) {
      message.params = Params.fromJSON(object.params);
    } else {
      message.params = undefined;
    }
    return message;
  },

  toJSON(message: QueryParamsResponse): unknown {
    const obj: any = {};
    message.params !== undefined &&
      (obj.params = message.params ? Params.toJSON(message.params) : undefined);
    return obj;
  },

  fromPartial(object: DeepPartial<QueryParamsResponse>): QueryParamsResponse {
    const message = { ...baseQueryParamsResponse } as QueryParamsResponse;
    if (object.params !== undefined && object.params !== null) {
      message.params = Params.fromPartial(object.params);
    } else {
      message.params = undefined;
    }
    return message;
  },
};

const baseQueryGetNextAuctionRequest: object = {};

export const QueryGetNextAuctionRequest = {
  encode(
    _: QueryGetNextAuctionRequest,
    writer: Writer = Writer.create()
  ): Writer {
    return writer;
  },

  decode(
    input: Reader | Uint8Array,
    length?: number
  ): QueryGetNextAuctionRequest {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = {
      ...baseQueryGetNextAuctionRequest,
    } as QueryGetNextAuctionRequest;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(_: any): QueryGetNextAuctionRequest {
    const message = {
      ...baseQueryGetNextAuctionRequest,
    } as QueryGetNextAuctionRequest;
    return message;
  },

  toJSON(_: QueryGetNextAuctionRequest): unknown {
    const obj: any = {};
    return obj;
  },

  fromPartial(
    _: DeepPartial<QueryGetNextAuctionRequest>
  ): QueryGetNextAuctionRequest {
    const message = {
      ...baseQueryGetNextAuctionRequest,
    } as QueryGetNextAuctionRequest;
    return message;
  },
};

const baseQueryGetNextAuctionResponse: object = {};

export const QueryGetNextAuctionResponse = {
  encode(
    message: QueryGetNextAuctionResponse,
    writer: Writer = Writer.create()
  ): Writer {
    if (message.NextAuction !== undefined) {
      NextAuction.encode(
        message.NextAuction,
        writer.uint32(10).fork()
      ).ldelim();
    }
    return writer;
  },

  decode(
    input: Reader | Uint8Array,
    length?: number
  ): QueryGetNextAuctionResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = {
      ...baseQueryGetNextAuctionResponse,
    } as QueryGetNextAuctionResponse;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.NextAuction = NextAuction.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(object: any): QueryGetNextAuctionResponse {
    const message = {
      ...baseQueryGetNextAuctionResponse,
    } as QueryGetNextAuctionResponse;
    if (object.NextAuction !== undefined && object.NextAuction !== null) {
      message.NextAuction = NextAuction.fromJSON(object.NextAuction);
    } else {
      message.NextAuction = undefined;
    }
    return message;
  },

  toJSON(message: QueryGetNextAuctionResponse): unknown {
    const obj: any = {};
    message.NextAuction !== undefined &&
      (obj.NextAuction = message.NextAuction
        ? NextAuction.toJSON(message.NextAuction)
        : undefined);
    return obj;
  },

  fromPartial(
    object: DeepPartial<QueryGetNextAuctionResponse>
  ): QueryGetNextAuctionResponse {
    const message = {
      ...baseQueryGetNextAuctionResponse,
    } as QueryGetNextAuctionResponse;
    if (object.NextAuction !== undefined && object.NextAuction !== null) {
      message.NextAuction = NextAuction.fromPartial(object.NextAuction);
    } else {
      message.NextAuction = undefined;
    }
    return message;
  },
};

const baseQueryGetAuctionRequest: object = { index: "" };

export const QueryGetAuctionRequest = {
  encode(
    message: QueryGetAuctionRequest,
    writer: Writer = Writer.create()
  ): Writer {
    if (message.index !== "") {
      writer.uint32(10).string(message.index);
    }
    return writer;
  },

  decode(input: Reader | Uint8Array, length?: number): QueryGetAuctionRequest {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = { ...baseQueryGetAuctionRequest } as QueryGetAuctionRequest;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.index = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(object: any): QueryGetAuctionRequest {
    const message = { ...baseQueryGetAuctionRequest } as QueryGetAuctionRequest;
    if (object.index !== undefined && object.index !== null) {
      message.index = String(object.index);
    } else {
      message.index = "";
    }
    return message;
  },

  toJSON(message: QueryGetAuctionRequest): unknown {
    const obj: any = {};
    message.index !== undefined && (obj.index = message.index);
    return obj;
  },

  fromPartial(
    object: DeepPartial<QueryGetAuctionRequest>
  ): QueryGetAuctionRequest {
    const message = { ...baseQueryGetAuctionRequest } as QueryGetAuctionRequest;
    if (object.index !== undefined && object.index !== null) {
      message.index = object.index;
    } else {
      message.index = "";
    }
    return message;
  },
};

const baseQueryGetAuctionResponse: object = {};

export const QueryGetAuctionResponse = {
  encode(
    message: QueryGetAuctionResponse,
    writer: Writer = Writer.create()
  ): Writer {
    if (message.auction !== undefined) {
      Auction.encode(message.auction, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: Reader | Uint8Array, length?: number): QueryGetAuctionResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = {
      ...baseQueryGetAuctionResponse,
    } as QueryGetAuctionResponse;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.auction = Auction.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(object: any): QueryGetAuctionResponse {
    const message = {
      ...baseQueryGetAuctionResponse,
    } as QueryGetAuctionResponse;
    if (object.auction !== undefined && object.auction !== null) {
      message.auction = Auction.fromJSON(object.auction);
    } else {
      message.auction = undefined;
    }
    return message;
  },

  toJSON(message: QueryGetAuctionResponse): unknown {
    const obj: any = {};
    message.auction !== undefined &&
      (obj.auction = message.auction
        ? Auction.toJSON(message.auction)
        : undefined);
    return obj;
  },

  fromPartial(
    object: DeepPartial<QueryGetAuctionResponse>
  ): QueryGetAuctionResponse {
    const message = {
      ...baseQueryGetAuctionResponse,
    } as QueryGetAuctionResponse;
    if (object.auction !== undefined && object.auction !== null) {
      message.auction = Auction.fromPartial(object.auction);
    } else {
      message.auction = undefined;
    }
    return message;
  },
};

const baseQueryAllAuctionRequest: object = {};

export const QueryAllAuctionRequest = {
  encode(
    message: QueryAllAuctionRequest,
    writer: Writer = Writer.create()
  ): Writer {
    if (message.pagination !== undefined) {
      PageRequest.encode(message.pagination, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: Reader | Uint8Array, length?: number): QueryAllAuctionRequest {
    const reader = input instanceof Uint8Array ? new Reader(input) : input;
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = { ...baseQueryAllAuctionRequest } as QueryAllAuctionRequest;
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.pagination = PageRequest.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },

  fromJSON(object: any): QueryAllAuctionRequest {
    const message = { ...baseQueryAllAuctionRequest } as QueryAllAuctionRequest;
    if (object.pagination !== undefined && object.pagination !== null) {
      message.pagination = PageRequest.fromJSON(object.pagination);
    } else {
      message.pagination = undefined;
    }
    return message;
  },

  toJSON(message: QueryAllAuctionRequest): unknown {
    const obj: any = {};
    message.pagination !== undefined &&
      (obj.pagination = message.pagination
        ? PageRequest.toJSON(message.pagination)
        : undefined);
    return obj;
  },

  fromPartial(
    object: DeepPartial<QueryAllAuctionRequest>
  ): QueryAllAuctionRequest {
    const message = { ...baseQueryAllAuctionRequest } as QueryAllAuctionRequest;
    if (object.pagination !== undefined && object.pagination !== null) {
      message.pagination = PageRequest.fromPartial(object.pagination);
    } else {
      message.pagination = undefined;
    }
    return message;
  },
};

const baseQueryAllAuctionResponse: object = {};

export const QueryAllAuctionResponse = {
  encode(
    message: QueryAllAuctionResponse,
    writer: Writer = Writer.create()
  ): Writer {
    for (const v of message.auction) {
      Auction.encode(v!, writer.uint32(10).fork()).ldelim();
    }
    if (message.pagination !== undefined) {
      PageResponse.encode(
        message.pagination,
        writer.uint32(18).fork()
      ).ldelim();
    }
    return writer;
  },

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

  fromJSON(object: any): QueryAllAuctionResponse {
    const message = {
      ...baseQueryAllAuctionResponse,
    } as QueryAllAuctionResponse;
    message.auction = [];
    if (object.auction !== undefined && object.auction !== null) {
      for (const e of object.auction) {
        message.auction.push(Auction.fromJSON(e));
      }
    }
    if (object.pagination !== undefined && object.pagination !== null) {
      message.pagination = PageResponse.fromJSON(object.pagination);
    } else {
      message.pagination = undefined;
    }
    return message;
  },

  toJSON(message: QueryAllAuctionResponse): unknown {
    const obj: any = {};
    if (message.auction) {
      obj.auction = message.auction.map((e) =>
        e ? Auction.toJSON(e) : undefined
      );
    } else {
      obj.auction = [];
    }
    message.pagination !== undefined &&
      (obj.pagination = message.pagination
        ? PageResponse.toJSON(message.pagination)
        : undefined);
    return obj;
  },

  fromPartial(
    object: DeepPartial<QueryAllAuctionResponse>
  ): QueryAllAuctionResponse {
    const message = {
      ...baseQueryAllAuctionResponse,
    } as QueryAllAuctionResponse;
    message.auction = [];
    if (object.auction !== undefined && object.auction !== null) {
      for (const e of object.auction) {
        message.auction.push(Auction.fromPartial(e));
      }
    }
    if (object.pagination !== undefined && object.pagination !== null) {
      message.pagination = PageResponse.fromPartial(object.pagination);
    } else {
      message.pagination = undefined;
    }
    return message;
  },
};

/** Query defines the gRPC querier service. */
export interface Query {
  /** Parameters queries the parameters of the module. */
  Params(request: QueryParamsRequest): Promise<QueryParamsResponse>;
  /** Queries a NextAuction by index. */
  NextAuction(
    request: QueryGetNextAuctionRequest
  ): Promise<QueryGetNextAuctionResponse>;
  /** Queries a Auction by index. */
  Auction(request: QueryGetAuctionRequest): Promise<QueryGetAuctionResponse>;
  /** Queries a list of Auction items. */
  AuctionAll(request: QueryAllAuctionRequest): Promise<QueryAllAuctionResponse>;
}

export class QueryClientImpl implements Query {
  private readonly rpc: Rpc;
  constructor(rpc: Rpc) {
    this.rpc = rpc;
  }
  Params(request: QueryParamsRequest): Promise<QueryParamsResponse> {
    const data = QueryParamsRequest.encode(request).finish();
    const promise = this.rpc.request(
      "cosmostest.cosmostest.Query",
      "Params",
      data
    );
    return promise.then((data) => QueryParamsResponse.decode(new Reader(data)));
  }

  NextAuction(
    request: QueryGetNextAuctionRequest
  ): Promise<QueryGetNextAuctionResponse> {
    const data = QueryGetNextAuctionRequest.encode(request).finish();
    const promise = this.rpc.request(
      "cosmostest.cosmostest.Query",
      "NextAuction",
      data
    );
    return promise.then((data) =>
      QueryGetNextAuctionResponse.decode(new Reader(data))
    );
  }

  Auction(request: QueryGetAuctionRequest): Promise<QueryGetAuctionResponse> {
    const data = QueryGetAuctionRequest.encode(request).finish();
    const promise = this.rpc.request(
      "cosmostest.cosmostest.Query",
      "Auction",
      data
    );
    return promise.then((data) =>
      QueryGetAuctionResponse.decode(new Reader(data))
    );
  }

  AuctionAll(
    request: QueryAllAuctionRequest
  ): Promise<QueryAllAuctionResponse> {
    const data = QueryAllAuctionRequest.encode(request).finish();
    const promise = this.rpc.request(
      "cosmostest.cosmostest.Query",
      "AuctionAll",
      data
    );
    return promise.then((data) =>
      QueryAllAuctionResponse.decode(new Reader(data))
    );
  }
}

interface Rpc {
  request(
    service: string,
    method: string,
    data: Uint8Array
  ): Promise<Uint8Array>;
}

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>;
