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