import { CounterpartyInfo } from "./counterparty";
import { BinaryReader, BinaryWriter } from "../../../../binary";
import { GlobalDecoderRegistry } from "../../../../registry";
function createBaseGenesisCounterpartyInfo() {
    return {
        clientId: "",
        counterpartyInfo: CounterpartyInfo.fromPartial({})
    };
}
/**
 * GenesisCounterpartyInfo defines the state associating a client with a counterparty.
 * @name GenesisCounterpartyInfo
 * @package ibc.core.client.v2
 * @see proto type: ibc.core.client.v2.GenesisCounterpartyInfo
 */
export const GenesisCounterpartyInfo = {
    typeUrl: "/ibc.core.client.v2.GenesisCounterpartyInfo",
    aminoType: "cosmos-sdk/GenesisCounterpartyInfo",
    is(o) {
        return o && (o.$typeUrl === GenesisCounterpartyInfo.typeUrl || typeof o.clientId === "string" && CounterpartyInfo.is(o.counterpartyInfo));
    },
    isAmino(o) {
        return o && (o.$typeUrl === GenesisCounterpartyInfo.typeUrl || typeof o.client_id === "string" && CounterpartyInfo.isAmino(o.counterparty_info));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.clientId !== "") {
            writer.uint32(10).string(message.clientId);
        }
        if (message.counterpartyInfo !== undefined) {
            CounterpartyInfo.encode(message.counterpartyInfo, 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 = createBaseGenesisCounterpartyInfo();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clientId = reader.string();
                    break;
                case 2:
                    message.counterpartyInfo = CounterpartyInfo.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseGenesisCounterpartyInfo();
        message.clientId = object.clientId ?? "";
        message.counterpartyInfo = object.counterpartyInfo !== undefined && object.counterpartyInfo !== null ? CounterpartyInfo.fromPartial(object.counterpartyInfo) : undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseGenesisCounterpartyInfo();
        if (object.client_id !== undefined && object.client_id !== null) {
            message.clientId = object.client_id;
        }
        if (object.counterparty_info !== undefined && object.counterparty_info !== null) {
            message.counterpartyInfo = CounterpartyInfo.fromAmino(object.counterparty_info);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.client_id = message.clientId === "" ? undefined : message.clientId;
        obj.counterparty_info = message.counterpartyInfo ? CounterpartyInfo.toAmino(message.counterpartyInfo) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return GenesisCounterpartyInfo.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/GenesisCounterpartyInfo",
            value: GenesisCounterpartyInfo.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return GenesisCounterpartyInfo.decode(message.value);
    },
    toProto(message) {
        return GenesisCounterpartyInfo.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.core.client.v2.GenesisCounterpartyInfo",
            value: GenesisCounterpartyInfo.encode(message).finish()
        };
    },
    registerTypeUrl() {
        if (!GlobalDecoderRegistry.registerExistingTypeUrl(GenesisCounterpartyInfo.typeUrl)) {
            return;
        }
        CounterpartyInfo.registerTypeUrl();
    }
};
function createBaseGenesisState() {
    return {
        counterpartyInfos: []
    };
}
/**
 * GenesisState defines the ibc client v2 submodule's genesis state.
 * @name GenesisState
 * @package ibc.core.client.v2
 * @see proto type: ibc.core.client.v2.GenesisState
 */
export const GenesisState = {
    typeUrl: "/ibc.core.client.v2.GenesisState",
    aminoType: "cosmos-sdk/GenesisState",
    is(o) {
        return o && (o.$typeUrl === GenesisState.typeUrl || Array.isArray(o.counterpartyInfos) && (!o.counterpartyInfos.length || GenesisCounterpartyInfo.is(o.counterpartyInfos[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === GenesisState.typeUrl || Array.isArray(o.counterparty_infos) && (!o.counterparty_infos.length || GenesisCounterpartyInfo.isAmino(o.counterparty_infos[0])));
    },
    encode(message, writer = BinaryWriter.create()) {
        for (const v of message.counterpartyInfos) {
            GenesisCounterpartyInfo.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 = createBaseGenesisState();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.counterpartyInfos.push(GenesisCounterpartyInfo.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseGenesisState();
        message.counterpartyInfos = object.counterpartyInfos?.map(e => GenesisCounterpartyInfo.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseGenesisState();
        message.counterpartyInfos = object.counterparty_infos?.map(e => GenesisCounterpartyInfo.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.counterpartyInfos) {
            obj.counterparty_infos = message.counterpartyInfos.map(e => e ? GenesisCounterpartyInfo.toAmino(e) : undefined);
        }
        else {
            obj.counterparty_infos = message.counterpartyInfos;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return GenesisState.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/GenesisState",
            value: GenesisState.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return GenesisState.decode(message.value);
    },
    toProto(message) {
        return GenesisState.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.core.client.v2.GenesisState",
            value: GenesisState.encode(message).finish()
        };
    },
    registerTypeUrl() {
        if (!GlobalDecoderRegistry.registerExistingTypeUrl(GenesisState.typeUrl)) {
            return;
        }
        GenesisCounterpartyInfo.registerTypeUrl();
    }
};
