import { Hop } from "../v1/transfer";
import { BinaryReader, BinaryWriter } from "../../../../binary";
import { GlobalDecoderRegistry } from "../../../../registry";
function createBaseToken() {
    return {
        denom: Denom.fromPartial({}),
        amount: ""
    };
}
export const Token = {
    typeUrl: "/ibc.applications.transfer.v2.Token",
    aminoType: "cosmos-sdk/Token",
    is(o) {
        return o && (o.$typeUrl === Token.typeUrl || Denom.is(o.denom) && typeof o.amount === "string");
    },
    isAmino(o) {
        return o && (o.$typeUrl === Token.typeUrl || Denom.isAmino(o.denom) && typeof o.amount === "string");
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.denom !== undefined) {
            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 BinaryReader ? input : new 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 = 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 ? 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 = 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 ? Denom.toAmino(message.denom) : undefined;
        obj.amount = message.amount === "" ? undefined : message.amount;
        return obj;
    },
    fromAminoMsg(object) {
        return Token.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Token",
            value: Token.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return Token.decode(message.value);
    },
    toProto(message) {
        return Token.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.Token",
            value: Token.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(Token.typeUrl, Token);
GlobalDecoderRegistry.registerAminoProtoMapping(Token.aminoType, Token.typeUrl);
function createBaseDenom() {
    return {
        base: "",
        trace: []
    };
}
export const Denom = {
    typeUrl: "/ibc.applications.transfer.v2.Denom",
    aminoType: "cosmos-sdk/Denom",
    is(o) {
        return o && (o.$typeUrl === Denom.typeUrl || typeof o.base === "string" && Array.isArray(o.trace) && (!o.trace.length || Hop.is(o.trace[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === Denom.typeUrl || typeof o.base === "string" && Array.isArray(o.trace) && (!o.trace.length || Hop.isAmino(o.trace[0])));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.base !== "") {
            writer.uint32(10).string(message.base);
        }
        for (const v of message.trace) {
            Hop.encode(v, writer.uint32(26).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 = createBaseDenom();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.base = reader.string();
                    break;
                case 3:
                    message.trace.push(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 => 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 => 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 ? Hop.toAmino(e) : undefined);
        }
        else {
            obj.trace = message.trace;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return Denom.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Denom",
            value: Denom.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return Denom.decode(message.value);
    },
    toProto(message) {
        return Denom.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.Denom",
            value: Denom.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(Denom.typeUrl, Denom);
GlobalDecoderRegistry.registerAminoProtoMapping(Denom.aminoType, Denom.typeUrl);
