import { Any } from "../../../../google/protobuf/any";
import { BinaryReader, BinaryWriter } from "../../../../binary";
import { GlobalDecoderRegistry } from "../../../../registry";
function createBaseQueryRequest() {
    return {
        request: undefined
    };
}
export const QueryRequest = {
    typeUrl: "/cosmos.base.grpc.v2.QueryRequest",
    aminoType: "cosmos-sdk/QueryRequest",
    is(o) {
        return o && o.$typeUrl === QueryRequest.typeUrl;
    },
    isAmino(o) {
        return o && o.$typeUrl === QueryRequest.typeUrl;
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.request !== undefined) {
            Any.encode(message.request, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseQueryRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.request = Any.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseQueryRequest();
        message.request = object.request !== undefined && object.request !== null ? Any.fromPartial(object.request) : undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseQueryRequest();
        if (object.request !== undefined && object.request !== null) {
            message.request = Any.fromAmino(object.request);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.request = message.request ? Any.toAmino(message.request) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return QueryRequest.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/QueryRequest",
            value: QueryRequest.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return QueryRequest.decode(message.value);
    },
    toProto(message) {
        return QueryRequest.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.base.grpc.v2.QueryRequest",
            value: QueryRequest.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(QueryRequest.typeUrl, QueryRequest);
GlobalDecoderRegistry.registerAminoProtoMapping(QueryRequest.aminoType, QueryRequest.typeUrl);
function createBaseQueryResponse() {
    return {
        response: undefined
    };
}
export const QueryResponse = {
    typeUrl: "/cosmos.base.grpc.v2.QueryResponse",
    aminoType: "cosmos-sdk/QueryResponse",
    is(o) {
        return o && o.$typeUrl === QueryResponse.typeUrl;
    },
    isAmino(o) {
        return o && o.$typeUrl === QueryResponse.typeUrl;
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.response !== undefined) {
            Any.encode(message.response, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseQueryResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.response = Any.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseQueryResponse();
        message.response = object.response !== undefined && object.response !== null ? Any.fromPartial(object.response) : undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseQueryResponse();
        if (object.response !== undefined && object.response !== null) {
            message.response = Any.fromAmino(object.response);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.response = message.response ? Any.toAmino(message.response) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return QueryResponse.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/QueryResponse",
            value: QueryResponse.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return QueryResponse.decode(message.value);
    },
    toProto(message) {
        return QueryResponse.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.base.grpc.v2.QueryResponse",
            value: QueryResponse.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(QueryResponse.typeUrl, QueryResponse);
GlobalDecoderRegistry.registerAminoProtoMapping(QueryResponse.aminoType, QueryResponse.typeUrl);
function createBaseListQueryHandlersRequest() {
    return {};
}
export const ListQueryHandlersRequest = {
    typeUrl: "/cosmos.base.grpc.v2.ListQueryHandlersRequest",
    aminoType: "cosmos-sdk/ListQueryHandlersRequest",
    is(o) {
        return o && o.$typeUrl === ListQueryHandlersRequest.typeUrl;
    },
    isAmino(o) {
        return o && o.$typeUrl === ListQueryHandlersRequest.typeUrl;
    },
    encode(_, writer = BinaryWriter.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseListQueryHandlersRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(_) {
        const message = createBaseListQueryHandlersRequest();
        return message;
    },
    fromAmino(_) {
        const message = createBaseListQueryHandlersRequest();
        return message;
    },
    toAmino(_) {
        const obj = {};
        return obj;
    },
    fromAminoMsg(object) {
        return ListQueryHandlersRequest.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/ListQueryHandlersRequest",
            value: ListQueryHandlersRequest.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return ListQueryHandlersRequest.decode(message.value);
    },
    toProto(message) {
        return ListQueryHandlersRequest.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.base.grpc.v2.ListQueryHandlersRequest",
            value: ListQueryHandlersRequest.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(ListQueryHandlersRequest.typeUrl, ListQueryHandlersRequest);
GlobalDecoderRegistry.registerAminoProtoMapping(ListQueryHandlersRequest.aminoType, ListQueryHandlersRequest.typeUrl);
function createBaseListQueryHandlersResponse() {
    return {
        handlers: []
    };
}
export const ListQueryHandlersResponse = {
    typeUrl: "/cosmos.base.grpc.v2.ListQueryHandlersResponse",
    aminoType: "cosmos-sdk/ListQueryHandlersResponse",
    is(o) {
        return o && (o.$typeUrl === ListQueryHandlersResponse.typeUrl || Array.isArray(o.handlers) && (!o.handlers.length || Handler.is(o.handlers[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === ListQueryHandlersResponse.typeUrl || Array.isArray(o.handlers) && (!o.handlers.length || Handler.isAmino(o.handlers[0])));
    },
    encode(message, writer = BinaryWriter.create()) {
        for (const v of message.handlers) {
            Handler.encode(v, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseListQueryHandlersResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.handlers.push(Handler.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseListQueryHandlersResponse();
        message.handlers = object.handlers?.map(e => Handler.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseListQueryHandlersResponse();
        message.handlers = object.handlers?.map(e => Handler.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.handlers) {
            obj.handlers = message.handlers.map(e => e ? Handler.toAmino(e) : undefined);
        }
        else {
            obj.handlers = message.handlers;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return ListQueryHandlersResponse.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/ListQueryHandlersResponse",
            value: ListQueryHandlersResponse.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return ListQueryHandlersResponse.decode(message.value);
    },
    toProto(message) {
        return ListQueryHandlersResponse.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.base.grpc.v2.ListQueryHandlersResponse",
            value: ListQueryHandlersResponse.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(ListQueryHandlersResponse.typeUrl, ListQueryHandlersResponse);
GlobalDecoderRegistry.registerAminoProtoMapping(ListQueryHandlersResponse.aminoType, ListQueryHandlersResponse.typeUrl);
function createBaseHandler() {
    return {
        requestName: "",
        responseName: ""
    };
}
export const Handler = {
    typeUrl: "/cosmos.base.grpc.v2.Handler",
    aminoType: "cosmos-sdk/Handler",
    is(o) {
        return o && (o.$typeUrl === Handler.typeUrl || typeof o.requestName === "string" && typeof o.responseName === "string");
    },
    isAmino(o) {
        return o && (o.$typeUrl === Handler.typeUrl || typeof o.request_name === "string" && typeof o.response_name === "string");
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.requestName !== "") {
            writer.uint32(10).string(message.requestName);
        }
        if (message.responseName !== "") {
            writer.uint32(18).string(message.responseName);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseHandler();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.requestName = reader.string();
                    break;
                case 2:
                    message.responseName = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseHandler();
        message.requestName = object.requestName ?? "";
        message.responseName = object.responseName ?? "";
        return message;
    },
    fromAmino(object) {
        const message = createBaseHandler();
        if (object.request_name !== undefined && object.request_name !== null) {
            message.requestName = object.request_name;
        }
        if (object.response_name !== undefined && object.response_name !== null) {
            message.responseName = object.response_name;
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.request_name = message.requestName === "" ? undefined : message.requestName;
        obj.response_name = message.responseName === "" ? undefined : message.responseName;
        return obj;
    },
    fromAminoMsg(object) {
        return Handler.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Handler",
            value: Handler.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return Handler.decode(message.value);
    },
    toProto(message) {
        return Handler.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.base.grpc.v2.Handler",
            value: Handler.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(Handler.typeUrl, Handler);
GlobalDecoderRegistry.registerAminoProtoMapping(Handler.aminoType, Handler.typeUrl);
