"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CounterpartyInfo = void 0;
const binary_1 = require("../../../../binary");
const helpers_1 = require("../../../../helpers");
function createBaseCounterpartyInfo() {
    return {
        merklePrefix: [],
        clientId: ""
    };
}
/**
 * CounterpartyInfo defines the key that the counterparty will use to message our client
 * @name CounterpartyInfo
 * @package ibc.core.client.v2
 * @see proto type: ibc.core.client.v2.CounterpartyInfo
 */
exports.CounterpartyInfo = {
    typeUrl: "/ibc.core.client.v2.CounterpartyInfo",
    aminoType: "cosmos-sdk/CounterpartyInfo",
    is(o) {
        return o && (o.$typeUrl === exports.CounterpartyInfo.typeUrl || Array.isArray(o.merklePrefix) && (!o.merklePrefix.length || o.merklePrefix[0] instanceof Uint8Array || typeof o.merklePrefix[0] === "string") && typeof o.clientId === "string");
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.CounterpartyInfo.typeUrl || Array.isArray(o.merkle_prefix) && (!o.merkle_prefix.length || o.merkle_prefix[0] instanceof Uint8Array || typeof o.merkle_prefix[0] === "string") && typeof o.client_id === "string");
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        for (const v of message.merklePrefix) {
            writer.uint32(10).bytes(v);
        }
        if (message.clientId !== "") {
            writer.uint32(18).string(message.clientId);
        }
        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 = createBaseCounterpartyInfo();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.merklePrefix.push(reader.bytes());
                    break;
                case 2:
                    message.clientId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseCounterpartyInfo();
        message.merklePrefix = object.merklePrefix?.map(e => e) || [];
        message.clientId = object.clientId ?? "";
        return message;
    },
    fromAmino(object) {
        const message = createBaseCounterpartyInfo();
        message.merklePrefix = object.merkle_prefix?.map(e => (0, helpers_1.bytesFromBase64)(e)) || [];
        if (object.client_id !== undefined && object.client_id !== null) {
            message.clientId = object.client_id;
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.merklePrefix) {
            obj.merkle_prefix = message.merklePrefix.map(e => (0, helpers_1.base64FromBytes)(e));
        }
        else {
            obj.merkle_prefix = message.merklePrefix;
        }
        obj.client_id = message.clientId === "" ? undefined : message.clientId;
        return obj;
    },
    fromAminoMsg(object) {
        return exports.CounterpartyInfo.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/CounterpartyInfo",
            value: exports.CounterpartyInfo.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.CounterpartyInfo.decode(message.value);
    },
    toProto(message) {
        return exports.CounterpartyInfo.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.core.client.v2.CounterpartyInfo",
            value: exports.CounterpartyInfo.encode(message).finish()
        };
    },
    registerTypeUrl() { }
};
