"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransferAuthorization = exports.Allocation = void 0;
const coin_1 = require("../../../../cosmos/base/v1beta1/coin");
const binary_1 = require("../../../../binary");
function createBaseAllocation() {
    return {
        sourcePort: "",
        sourceChannel: "",
        spendLimit: [],
        allowList: []
    };
}
exports.Allocation = {
    typeUrl: "/ibc.applications.transfer.v1.Allocation",
    aminoType: "cosmos-sdk/Allocation",
    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);
        }
        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;
                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) || [];
        return message;
    },
    fromAmino(object) {
        return {
            sourcePort: object.source_port,
            sourceChannel: object.source_channel,
            spendLimit: Array.isArray(object?.spend_limit) ? object.spend_limit.map((e) => coin_1.Coin.fromAmino(e)) : [],
            allowList: Array.isArray(object?.allow_list) ? object.allow_list.map((e) => e) : []
        };
    },
    toAmino(message) {
        const obj = {};
        obj.source_port = message.sourcePort;
        obj.source_channel = message.sourceChannel;
        if (message.spendLimit) {
            obj.spend_limit = message.spendLimit.map(e => e ? coin_1.Coin.toAmino(e) : undefined);
        }
        else {
            obj.spend_limit = [];
        }
        if (message.allowList) {
            obj.allow_list = message.allowList.map(e => e);
        }
        else {
            obj.allow_list = [];
        }
        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()
        };
    }
};
function createBaseTransferAuthorization() {
    return {
        $typeUrl: "/ibc.applications.transfer.v1.TransferAuthorization",
        allocations: []
    };
}
exports.TransferAuthorization = {
    typeUrl: "/ibc.applications.transfer.v1.TransferAuthorization",
    aminoType: "cosmos-sdk/TransferAuthorization",
    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) {
        return {
            allocations: Array.isArray(object?.allocations) ? object.allocations.map((e) => exports.Allocation.fromAmino(e)) : []
        };
    },
    toAmino(message) {
        const obj = {};
        if (message.allocations) {
            obj.allocations = message.allocations.map(e => e ? exports.Allocation.toAmino(e) : undefined);
        }
        else {
            obj.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()
        };
    }
};
//# sourceMappingURL=authz.js.map