"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenesisState = exports.GenesisCounterpartyInfo = void 0;
const counterparty_1 = require("./counterparty");
const binary_1 = require("../../../../binary");
const registry_1 = require("../../../../registry");
function createBaseGenesisCounterpartyInfo() {
    return {
        clientId: "",
        counterpartyInfo: counterparty_1.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
 */
exports.GenesisCounterpartyInfo = {
    typeUrl: "/ibc.core.client.v2.GenesisCounterpartyInfo",
    aminoType: "cosmos-sdk/GenesisCounterpartyInfo",
    is(o) {
        return o && (o.$typeUrl === exports.GenesisCounterpartyInfo.typeUrl || typeof o.clientId === "string" && counterparty_1.CounterpartyInfo.is(o.counterpartyInfo));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.GenesisCounterpartyInfo.typeUrl || typeof o.client_id === "string" && counterparty_1.CounterpartyInfo.isAmino(o.counterparty_info));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.clientId !== "") {
            writer.uint32(10).string(message.clientId);
        }
        if (message.counterpartyInfo !== undefined) {
            counterparty_1.CounterpartyInfo.encode(message.counterpartyInfo, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof binary_1.BinaryReader ? input : new binary_1.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 = counterparty_1.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 ? counterparty_1.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 = counterparty_1.CounterpartyInfo.fromAmino(object.counterparty_info);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.client_id = message.clientId === "" ? undefined : message.clientId;
        obj.counterparty_info = message.counterpartyInfo ? counterparty_1.CounterpartyInfo.toAmino(message.counterpartyInfo) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return exports.GenesisCounterpartyInfo.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/GenesisCounterpartyInfo",
            value: exports.GenesisCounterpartyInfo.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.GenesisCounterpartyInfo.decode(message.value);
    },
    toProto(message) {
        return exports.GenesisCounterpartyInfo.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.core.client.v2.GenesisCounterpartyInfo",
            value: exports.GenesisCounterpartyInfo.encode(message).finish()
        };
    },
    registerTypeUrl() {
        if (!registry_1.GlobalDecoderRegistry.registerExistingTypeUrl(exports.GenesisCounterpartyInfo.typeUrl)) {
            return;
        }
        counterparty_1.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
 */
exports.GenesisState = {
    typeUrl: "/ibc.core.client.v2.GenesisState",
    aminoType: "cosmos-sdk/GenesisState",
    is(o) {
        return o && (o.$typeUrl === exports.GenesisState.typeUrl || Array.isArray(o.counterpartyInfos) && (!o.counterpartyInfos.length || exports.GenesisCounterpartyInfo.is(o.counterpartyInfos[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.GenesisState.typeUrl || Array.isArray(o.counterparty_infos) && (!o.counterparty_infos.length || exports.GenesisCounterpartyInfo.isAmino(o.counterparty_infos[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        for (const v of message.counterpartyInfos) {
            exports.GenesisCounterpartyInfo.encode(v, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof binary_1.BinaryReader ? input : new binary_1.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(exports.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 => exports.GenesisCounterpartyInfo.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseGenesisState();
        message.counterpartyInfos = object.counterparty_infos?.map(e => exports.GenesisCounterpartyInfo.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.counterpartyInfos) {
            obj.counterparty_infos = message.counterpartyInfos.map(e => e ? exports.GenesisCounterpartyInfo.toAmino(e) : undefined);
        }
        else {
            obj.counterparty_infos = message.counterpartyInfos;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.GenesisState.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/GenesisState",
            value: exports.GenesisState.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.GenesisState.decode(message.value);
    },
    toProto(message) {
        return exports.GenesisState.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.core.client.v2.GenesisState",
            value: exports.GenesisState.encode(message).finish()
        };
    },
    registerTypeUrl() {
        if (!registry_1.GlobalDecoderRegistry.registerExistingTypeUrl(exports.GenesisState.typeUrl)) {
            return;
        }
        exports.GenesisCounterpartyInfo.registerTypeUrl();
    }
};
