"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransferAuthorization = exports.AllowedForwarding = exports.Allocation = void 0;
const coin_1 = require("../../../../cosmos/base/v1beta1/coin");
const transfer_1 = require("./transfer");
const binary_1 = require("../../../../binary");
const registry_1 = require("../../../../registry");
function createBaseAllocation() {
    return {
        sourcePort: "",
        sourceChannel: "",
        spendLimit: [],
        allowList: [],
        allowedPacketData: [],
        allowedForwarding: []
    };
}
exports.Allocation = {
    typeUrl: "/ibc.applications.transfer.v1.Allocation",
    aminoType: "cosmos-sdk/Allocation",
    is(o) {
        return o && (o.$typeUrl === exports.Allocation.typeUrl || typeof o.sourcePort === "string" && typeof o.sourceChannel === "string" && Array.isArray(o.spendLimit) && (!o.spendLimit.length || coin_1.Coin.is(o.spendLimit[0])) && Array.isArray(o.allowList) && (!o.allowList.length || typeof o.allowList[0] === "string") && Array.isArray(o.allowedPacketData) && (!o.allowedPacketData.length || typeof o.allowedPacketData[0] === "string") && Array.isArray(o.allowedForwarding) && (!o.allowedForwarding.length || exports.AllowedForwarding.is(o.allowedForwarding[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.Allocation.typeUrl || typeof o.source_port === "string" && typeof o.source_channel === "string" && Array.isArray(o.spend_limit) && (!o.spend_limit.length || coin_1.Coin.isAmino(o.spend_limit[0])) && Array.isArray(o.allow_list) && (!o.allow_list.length || typeof o.allow_list[0] === "string") && Array.isArray(o.allowed_packet_data) && (!o.allowed_packet_data.length || typeof o.allowed_packet_data[0] === "string") && Array.isArray(o.allowed_forwarding) && (!o.allowed_forwarding.length || exports.AllowedForwarding.isAmino(o.allowed_forwarding[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.sourcePort !== "") {
            writer.uint32(10).string(message.sourcePort);
        }
        if (message.sourceChannel !== "") {
            writer.uint32(18).string(message.sourceChannel);
        }
        for (const v of message.spendLimit) {
            coin_1.Coin.encode(v, writer.uint32(26).fork()).ldelim();
        }
        for (const v of message.allowList) {
            writer.uint32(34).string(v);
        }
        for (const v of message.allowedPacketData) {
            writer.uint32(42).string(v);
        }
        for (const v of message.allowedForwarding) {
            exports.AllowedForwarding.encode(v, writer.uint32(50).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 = createBaseAllocation();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.sourcePort = reader.string();
                    break;
                case 2:
                    message.sourceChannel = reader.string();
                    break;
                case 3:
                    message.spendLimit.push(coin_1.Coin.decode(reader, reader.uint32()));
                    break;
                case 4:
                    message.allowList.push(reader.string());
                    break;
                case 5:
                    message.allowedPacketData.push(reader.string());
                    break;
                case 6:
                    message.allowedForwarding.push(exports.AllowedForwarding.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseAllocation();
        message.sourcePort = object.sourcePort ?? "";
        message.sourceChannel = object.sourceChannel ?? "";
        message.spendLimit = object.spendLimit?.map(e => coin_1.Coin.fromPartial(e)) || [];
        message.allowList = object.allowList?.map(e => e) || [];
        message.allowedPacketData = object.allowedPacketData?.map(e => e) || [];
        message.allowedForwarding = object.allowedForwarding?.map(e => exports.AllowedForwarding.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseAllocation();
        if (object.source_port !== undefined && object.source_port !== null) {
            message.sourcePort = object.source_port;
        }
        if (object.source_channel !== undefined && object.source_channel !== null) {
            message.sourceChannel = object.source_channel;
        }
        message.spendLimit = object.spend_limit?.map(e => coin_1.Coin.fromAmino(e)) || [];
        message.allowList = object.allow_list?.map(e => e) || [];
        message.allowedPacketData = object.allowed_packet_data?.map(e => e) || [];
        message.allowedForwarding = object.allowed_forwarding?.map(e => exports.AllowedForwarding.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.source_port = message.sourcePort === "" ? undefined : message.sourcePort;
        obj.source_channel = message.sourceChannel === "" ? undefined : message.sourceChannel;
        if (message.spendLimit) {
            obj.spend_limit = message.spendLimit.map(e => e ? coin_1.Coin.toAmino(e) : undefined);
        }
        else {
            obj.spend_limit = message.spendLimit;
        }
        if (message.allowList) {
            obj.allow_list = message.allowList.map(e => e);
        }
        else {
            obj.allow_list = message.allowList;
        }
        if (message.allowedPacketData) {
            obj.allowed_packet_data = message.allowedPacketData.map(e => e);
        }
        else {
            obj.allowed_packet_data = message.allowedPacketData;
        }
        if (message.allowedForwarding) {
            obj.allowed_forwarding = message.allowedForwarding.map(e => e ? exports.AllowedForwarding.toAmino(e) : undefined);
        }
        else {
            obj.allowed_forwarding = message.allowedForwarding;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.Allocation.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Allocation",
            value: exports.Allocation.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.Allocation.decode(message.value);
    },
    toProto(message) {
        return exports.Allocation.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v1.Allocation",
            value: exports.Allocation.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.Allocation.typeUrl, exports.Allocation);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.Allocation.aminoType, exports.Allocation.typeUrl);
function createBaseAllowedForwarding() {
    return {
        hops: []
    };
}
exports.AllowedForwarding = {
    typeUrl: "/ibc.applications.transfer.v1.AllowedForwarding",
    aminoType: "cosmos-sdk/AllowedForwarding",
    is(o) {
        return o && (o.$typeUrl === exports.AllowedForwarding.typeUrl || Array.isArray(o.hops) && (!o.hops.length || transfer_1.Hop.is(o.hops[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.AllowedForwarding.typeUrl || Array.isArray(o.hops) && (!o.hops.length || transfer_1.Hop.isAmino(o.hops[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        for (const v of message.hops) {
            transfer_1.Hop.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 = createBaseAllowedForwarding();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.hops.push(transfer_1.Hop.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseAllowedForwarding();
        message.hops = object.hops?.map(e => transfer_1.Hop.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseAllowedForwarding();
        message.hops = object.hops?.map(e => transfer_1.Hop.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        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.AllowedForwarding.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/AllowedForwarding",
            value: exports.AllowedForwarding.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.AllowedForwarding.decode(message.value);
    },
    toProto(message) {
        return exports.AllowedForwarding.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v1.AllowedForwarding",
            value: exports.AllowedForwarding.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.AllowedForwarding.typeUrl, exports.AllowedForwarding);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.AllowedForwarding.aminoType, exports.AllowedForwarding.typeUrl);
function createBaseTransferAuthorization() {
    return {
        allocations: []
    };
}
exports.TransferAuthorization = {
    typeUrl: "/ibc.applications.transfer.v1.TransferAuthorization",
    aminoType: "cosmos-sdk/TransferAuthorization",
    is(o) {
        return o && (o.$typeUrl === exports.TransferAuthorization.typeUrl || Array.isArray(o.allocations) && (!o.allocations.length || exports.Allocation.is(o.allocations[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.TransferAuthorization.typeUrl || Array.isArray(o.allocations) && (!o.allocations.length || exports.Allocation.isAmino(o.allocations[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        for (const v of message.allocations) {
            exports.Allocation.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 = createBaseTransferAuthorization();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.allocations.push(exports.Allocation.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseTransferAuthorization();
        message.allocations = object.allocations?.map(e => exports.Allocation.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseTransferAuthorization();
        message.allocations = object.allocations?.map(e => exports.Allocation.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.allocations) {
            obj.allocations = message.allocations.map(e => e ? exports.Allocation.toAmino(e) : undefined);
        }
        else {
            obj.allocations = message.allocations;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.TransferAuthorization.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/TransferAuthorization",
            value: exports.TransferAuthorization.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.TransferAuthorization.decode(message.value);
    },
    toProto(message) {
        return exports.TransferAuthorization.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v1.TransferAuthorization",
            value: exports.TransferAuthorization.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.TransferAuthorization.typeUrl, exports.TransferAuthorization);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.TransferAuthorization.aminoType, exports.TransferAuthorization.typeUrl);
