import { Params, QueryRequest } from "./host";
import { BinaryReader, BinaryWriter } from "../../../../../binary";
import { GlobalDecoderRegistry } from "../../../../../registry";
import { bytesFromBase64, base64FromBytes } from "../../../../../helpers";
function createBaseMsgUpdateParams() {
    return {
        signer: "",
        params: Params.fromPartial({})
    };
}
export const MsgUpdateParams = {
    typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgUpdateParams",
    aminoType: "cosmos-sdk/MsgUpdateParams",
    is(o) {
        return o && (o.$typeUrl === MsgUpdateParams.typeUrl || typeof o.signer === "string" && Params.is(o.params));
    },
    isAmino(o) {
        return o && (o.$typeUrl === MsgUpdateParams.typeUrl || typeof o.signer === "string" && Params.isAmino(o.params));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.signer !== "") {
            writer.uint32(10).string(message.signer);
        }
        if (message.params !== undefined) {
            Params.encode(message.params, writer.uint32(18).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 = createBaseMsgUpdateParams();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.signer = reader.string();
                    break;
                case 2:
                    message.params = Params.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseMsgUpdateParams();
        message.signer = object.signer ?? "";
        message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseMsgUpdateParams();
        if (object.signer !== undefined && object.signer !== null) {
            message.signer = object.signer;
        }
        if (object.params !== undefined && object.params !== null) {
            message.params = Params.fromAmino(object.params);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.signer = message.signer === "" ? undefined : message.signer;
        obj.params = message.params ? Params.toAmino(message.params) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return MsgUpdateParams.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/MsgUpdateParams",
            value: MsgUpdateParams.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return MsgUpdateParams.decode(message.value);
    },
    toProto(message) {
        return MsgUpdateParams.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgUpdateParams",
            value: MsgUpdateParams.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(MsgUpdateParams.typeUrl, MsgUpdateParams);
GlobalDecoderRegistry.registerAminoProtoMapping(MsgUpdateParams.aminoType, MsgUpdateParams.typeUrl);
function createBaseMsgUpdateParamsResponse() {
    return {};
}
export const MsgUpdateParamsResponse = {
    typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgUpdateParamsResponse",
    aminoType: "cosmos-sdk/MsgUpdateParamsResponse",
    is(o) {
        return o && o.$typeUrl === MsgUpdateParamsResponse.typeUrl;
    },
    isAmino(o) {
        return o && o.$typeUrl === MsgUpdateParamsResponse.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 = createBaseMsgUpdateParamsResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(_) {
        const message = createBaseMsgUpdateParamsResponse();
        return message;
    },
    fromAmino(_) {
        const message = createBaseMsgUpdateParamsResponse();
        return message;
    },
    toAmino(_) {
        const obj = {};
        return obj;
    },
    fromAminoMsg(object) {
        return MsgUpdateParamsResponse.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/MsgUpdateParamsResponse",
            value: MsgUpdateParamsResponse.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return MsgUpdateParamsResponse.decode(message.value);
    },
    toProto(message) {
        return MsgUpdateParamsResponse.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgUpdateParamsResponse",
            value: MsgUpdateParamsResponse.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(MsgUpdateParamsResponse.typeUrl, MsgUpdateParamsResponse);
GlobalDecoderRegistry.registerAminoProtoMapping(MsgUpdateParamsResponse.aminoType, MsgUpdateParamsResponse.typeUrl);
function createBaseMsgModuleQuerySafe() {
    return {
        signer: "",
        requests: []
    };
}
export const MsgModuleQuerySafe = {
    typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe",
    aminoType: "cosmos-sdk/MsgModuleQuerySafe",
    is(o) {
        return o && (o.$typeUrl === MsgModuleQuerySafe.typeUrl || typeof o.signer === "string" && Array.isArray(o.requests) && (!o.requests.length || QueryRequest.is(o.requests[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === MsgModuleQuerySafe.typeUrl || typeof o.signer === "string" && Array.isArray(o.requests) && (!o.requests.length || QueryRequest.isAmino(o.requests[0])));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.signer !== "") {
            writer.uint32(10).string(message.signer);
        }
        for (const v of message.requests) {
            QueryRequest.encode(v, writer.uint32(18).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 = createBaseMsgModuleQuerySafe();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.signer = reader.string();
                    break;
                case 2:
                    message.requests.push(QueryRequest.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseMsgModuleQuerySafe();
        message.signer = object.signer ?? "";
        message.requests = object.requests?.map(e => QueryRequest.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseMsgModuleQuerySafe();
        if (object.signer !== undefined && object.signer !== null) {
            message.signer = object.signer;
        }
        message.requests = object.requests?.map(e => QueryRequest.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.signer = message.signer === "" ? undefined : message.signer;
        if (message.requests) {
            obj.requests = message.requests.map(e => e ? QueryRequest.toAmino(e) : undefined);
        }
        else {
            obj.requests = message.requests;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return MsgModuleQuerySafe.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/MsgModuleQuerySafe",
            value: MsgModuleQuerySafe.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return MsgModuleQuerySafe.decode(message.value);
    },
    toProto(message) {
        return MsgModuleQuerySafe.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe",
            value: MsgModuleQuerySafe.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(MsgModuleQuerySafe.typeUrl, MsgModuleQuerySafe);
GlobalDecoderRegistry.registerAminoProtoMapping(MsgModuleQuerySafe.aminoType, MsgModuleQuerySafe.typeUrl);
function createBaseMsgModuleQuerySafeResponse() {
    return {
        height: BigInt(0),
        responses: []
    };
}
export const MsgModuleQuerySafeResponse = {
    typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafeResponse",
    aminoType: "cosmos-sdk/MsgModuleQuerySafeResponse",
    is(o) {
        return o && (o.$typeUrl === MsgModuleQuerySafeResponse.typeUrl || typeof o.height === "bigint" && Array.isArray(o.responses) && (!o.responses.length || o.responses[0] instanceof Uint8Array || typeof o.responses[0] === "string"));
    },
    isAmino(o) {
        return o && (o.$typeUrl === MsgModuleQuerySafeResponse.typeUrl || typeof o.height === "bigint" && Array.isArray(o.responses) && (!o.responses.length || o.responses[0] instanceof Uint8Array || typeof o.responses[0] === "string"));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.height !== BigInt(0)) {
            writer.uint32(8).uint64(message.height);
        }
        for (const v of message.responses) {
            writer.uint32(18).bytes(v);
        }
        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 = createBaseMsgModuleQuerySafeResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.height = reader.uint64();
                    break;
                case 2:
                    message.responses.push(reader.bytes());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseMsgModuleQuerySafeResponse();
        message.height = object.height !== undefined && object.height !== null ? BigInt(object.height.toString()) : BigInt(0);
        message.responses = object.responses?.map(e => e) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseMsgModuleQuerySafeResponse();
        if (object.height !== undefined && object.height !== null) {
            message.height = BigInt(object.height);
        }
        message.responses = object.responses?.map(e => bytesFromBase64(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.height = message.height !== BigInt(0) ? message.height?.toString() : undefined;
        if (message.responses) {
            obj.responses = message.responses.map(e => base64FromBytes(e));
        }
        else {
            obj.responses = message.responses;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return MsgModuleQuerySafeResponse.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/MsgModuleQuerySafeResponse",
            value: MsgModuleQuerySafeResponse.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return MsgModuleQuerySafeResponse.decode(message.value);
    },
    toProto(message) {
        return MsgModuleQuerySafeResponse.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafeResponse",
            value: MsgModuleQuerySafeResponse.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(MsgModuleQuerySafeResponse.typeUrl, MsgModuleQuerySafeResponse);
GlobalDecoderRegistry.registerAminoProtoMapping(MsgModuleQuerySafeResponse.aminoType, MsgModuleQuerySafeResponse.typeUrl);
