"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Denom = exports.Token = void 0;
const transfer_1 = require("../v1/transfer");
const binary_1 = require("../../../../binary");
const registry_1 = require("../../../../registry");
function createBaseToken() {
    return {
        denom: exports.Denom.fromPartial({}),
        amount: ""
    };
}
exports.Token = {
    typeUrl: "/ibc.applications.transfer.v2.Token",
    aminoType: "cosmos-sdk/Token",
    is(o) {
        return o && (o.$typeUrl === exports.Token.typeUrl || exports.Denom.is(o.denom) && typeof o.amount === "string");
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.Token.typeUrl || exports.Denom.isAmino(o.denom) && typeof o.amount === "string");
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.denom !== undefined) {
            exports.Denom.encode(message.denom, writer.uint32(10).fork()).ldelim();
        }
        if (message.amount !== "") {
            writer.uint32(18).string(message.amount);
        }
        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 = createBaseToken();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.denom = exports.Denom.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.amount = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseToken();
        message.denom = object.denom !== undefined && object.denom !== null ? exports.Denom.fromPartial(object.denom) : undefined;
        message.amount = object.amount ?? "";
        return message;
    },
    fromAmino(object) {
        const message = createBaseToken();
        if (object.denom !== undefined && object.denom !== null) {
            message.denom = exports.Denom.fromAmino(object.denom);
        }
        if (object.amount !== undefined && object.amount !== null) {
            message.amount = object.amount;
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.denom = message.denom ? exports.Denom.toAmino(message.denom) : undefined;
        obj.amount = message.amount === "" ? undefined : message.amount;
        return obj;
    },
    fromAminoMsg(object) {
        return exports.Token.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Token",
            value: exports.Token.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.Token.decode(message.value);
    },
    toProto(message) {
        return exports.Token.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.Token",
            value: exports.Token.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.Token.typeUrl, exports.Token);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.Token.aminoType, exports.Token.typeUrl);
function createBaseDenom() {
    return {
        base: "",
        trace: []
    };
}
exports.Denom = {
    typeUrl: "/ibc.applications.transfer.v2.Denom",
    aminoType: "cosmos-sdk/Denom",
    is(o) {
        return o && (o.$typeUrl === exports.Denom.typeUrl || typeof o.base === "string" && Array.isArray(o.trace) && (!o.trace.length || transfer_1.Hop.is(o.trace[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.Denom.typeUrl || typeof o.base === "string" && Array.isArray(o.trace) && (!o.trace.length || transfer_1.Hop.isAmino(o.trace[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.base !== "") {
            writer.uint32(10).string(message.base);
        }
        for (const v of message.trace) {
            transfer_1.Hop.encode(v, writer.uint32(26).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 = createBaseDenom();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.base = reader.string();
                    break;
                case 3:
                    message.trace.push(transfer_1.Hop.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseDenom();
        message.base = object.base ?? "";
        message.trace = object.trace?.map(e => transfer_1.Hop.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseDenom();
        if (object.base !== undefined && object.base !== null) {
            message.base = object.base;
        }
        message.trace = object.trace?.map(e => transfer_1.Hop.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.base = message.base === "" ? undefined : message.base;
        if (message.trace) {
            obj.trace = message.trace.map(e => e ? transfer_1.Hop.toAmino(e) : undefined);
        }
        else {
            obj.trace = message.trace;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.Denom.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Denom",
            value: exports.Denom.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.Denom.decode(message.value);
    },
    toProto(message) {
        return exports.Denom.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.Denom",
            value: exports.Denom.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.Denom.typeUrl, exports.Denom);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.Denom.aminoType, exports.Denom.typeUrl);
