"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IdentifiedPacketFees = exports.PacketFees = exports.PacketFee = exports.Fee = void 0;
const coin_1 = require("../../../../cosmos/base/v1beta1/coin");
const channel_1 = require("../../../core/channel/v1/channel");
const binary_1 = require("../../../../binary");
const registry_1 = require("../../../../registry");
function createBaseFee() {
    return {
        recvFee: [],
        ackFee: [],
        timeoutFee: []
    };
}
exports.Fee = {
    typeUrl: "/ibc.applications.fee.v1.Fee",
    aminoType: "cosmos-sdk/Fee",
    is(o) {
        return o && (o.$typeUrl === exports.Fee.typeUrl || Array.isArray(o.recvFee) && (!o.recvFee.length || coin_1.Coin.is(o.recvFee[0])) && Array.isArray(o.ackFee) && (!o.ackFee.length || coin_1.Coin.is(o.ackFee[0])) && Array.isArray(o.timeoutFee) && (!o.timeoutFee.length || coin_1.Coin.is(o.timeoutFee[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.Fee.typeUrl || Array.isArray(o.recv_fee) && (!o.recv_fee.length || coin_1.Coin.isAmino(o.recv_fee[0])) && Array.isArray(o.ack_fee) && (!o.ack_fee.length || coin_1.Coin.isAmino(o.ack_fee[0])) && Array.isArray(o.timeout_fee) && (!o.timeout_fee.length || coin_1.Coin.isAmino(o.timeout_fee[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        for (const v of message.recvFee) {
            coin_1.Coin.encode(v, writer.uint32(10).fork()).ldelim();
        }
        for (const v of message.ackFee) {
            coin_1.Coin.encode(v, writer.uint32(18).fork()).ldelim();
        }
        for (const v of message.timeoutFee) {
            coin_1.Coin.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 = createBaseFee();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.recvFee.push(coin_1.Coin.decode(reader, reader.uint32()));
                    break;
                case 2:
                    message.ackFee.push(coin_1.Coin.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.timeoutFee.push(coin_1.Coin.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseFee();
        message.recvFee = object.recvFee?.map(e => coin_1.Coin.fromPartial(e)) || [];
        message.ackFee = object.ackFee?.map(e => coin_1.Coin.fromPartial(e)) || [];
        message.timeoutFee = object.timeoutFee?.map(e => coin_1.Coin.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseFee();
        message.recvFee = object.recv_fee?.map(e => coin_1.Coin.fromAmino(e)) || [];
        message.ackFee = object.ack_fee?.map(e => coin_1.Coin.fromAmino(e)) || [];
        message.timeoutFee = object.timeout_fee?.map(e => coin_1.Coin.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.recvFee) {
            obj.recv_fee = message.recvFee.map(e => e ? coin_1.Coin.toAmino(e) : undefined);
        }
        else {
            obj.recv_fee = message.recvFee;
        }
        if (message.ackFee) {
            obj.ack_fee = message.ackFee.map(e => e ? coin_1.Coin.toAmino(e) : undefined);
        }
        else {
            obj.ack_fee = message.ackFee;
        }
        if (message.timeoutFee) {
            obj.timeout_fee = message.timeoutFee.map(e => e ? coin_1.Coin.toAmino(e) : undefined);
        }
        else {
            obj.timeout_fee = message.timeoutFee;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.Fee.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Fee",
            value: exports.Fee.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.Fee.decode(message.value);
    },
    toProto(message) {
        return exports.Fee.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.fee.v1.Fee",
            value: exports.Fee.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.Fee.typeUrl, exports.Fee);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.Fee.aminoType, exports.Fee.typeUrl);
function createBasePacketFee() {
    return {
        fee: exports.Fee.fromPartial({}),
        refundAddress: "",
        relayers: []
    };
}
exports.PacketFee = {
    typeUrl: "/ibc.applications.fee.v1.PacketFee",
    aminoType: "cosmos-sdk/PacketFee",
    is(o) {
        return o && (o.$typeUrl === exports.PacketFee.typeUrl || exports.Fee.is(o.fee) && typeof o.refundAddress === "string" && Array.isArray(o.relayers) && (!o.relayers.length || typeof o.relayers[0] === "string"));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.PacketFee.typeUrl || exports.Fee.isAmino(o.fee) && typeof o.refund_address === "string" && Array.isArray(o.relayers) && (!o.relayers.length || typeof o.relayers[0] === "string"));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.fee !== undefined) {
            exports.Fee.encode(message.fee, writer.uint32(10).fork()).ldelim();
        }
        if (message.refundAddress !== "") {
            writer.uint32(18).string(message.refundAddress);
        }
        for (const v of message.relayers) {
            writer.uint32(26).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 = createBasePacketFee();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.fee = exports.Fee.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.refundAddress = reader.string();
                    break;
                case 3:
                    message.relayers.push(reader.string());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBasePacketFee();
        message.fee = object.fee !== undefined && object.fee !== null ? exports.Fee.fromPartial(object.fee) : undefined;
        message.refundAddress = object.refundAddress ?? "";
        message.relayers = object.relayers?.map(e => e) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBasePacketFee();
        if (object.fee !== undefined && object.fee !== null) {
            message.fee = exports.Fee.fromAmino(object.fee);
        }
        if (object.refund_address !== undefined && object.refund_address !== null) {
            message.refundAddress = object.refund_address;
        }
        message.relayers = object.relayers?.map(e => e) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.fee = message.fee ? exports.Fee.toAmino(message.fee) : undefined;
        obj.refund_address = message.refundAddress === "" ? undefined : message.refundAddress;
        if (message.relayers) {
            obj.relayers = message.relayers.map(e => e);
        }
        else {
            obj.relayers = message.relayers;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.PacketFee.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/PacketFee",
            value: exports.PacketFee.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.PacketFee.decode(message.value);
    },
    toProto(message) {
        return exports.PacketFee.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.fee.v1.PacketFee",
            value: exports.PacketFee.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.PacketFee.typeUrl, exports.PacketFee);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.PacketFee.aminoType, exports.PacketFee.typeUrl);
function createBasePacketFees() {
    return {
        packetFees: []
    };
}
exports.PacketFees = {
    typeUrl: "/ibc.applications.fee.v1.PacketFees",
    aminoType: "cosmos-sdk/PacketFees",
    is(o) {
        return o && (o.$typeUrl === exports.PacketFees.typeUrl || Array.isArray(o.packetFees) && (!o.packetFees.length || exports.PacketFee.is(o.packetFees[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.PacketFees.typeUrl || Array.isArray(o.packet_fees) && (!o.packet_fees.length || exports.PacketFee.isAmino(o.packet_fees[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        for (const v of message.packetFees) {
            exports.PacketFee.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 = createBasePacketFees();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.packetFees.push(exports.PacketFee.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBasePacketFees();
        message.packetFees = object.packetFees?.map(e => exports.PacketFee.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBasePacketFees();
        message.packetFees = object.packet_fees?.map(e => exports.PacketFee.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.packetFees) {
            obj.packet_fees = message.packetFees.map(e => e ? exports.PacketFee.toAmino(e) : undefined);
        }
        else {
            obj.packet_fees = message.packetFees;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.PacketFees.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/PacketFees",
            value: exports.PacketFees.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.PacketFees.decode(message.value);
    },
    toProto(message) {
        return exports.PacketFees.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.fee.v1.PacketFees",
            value: exports.PacketFees.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.PacketFees.typeUrl, exports.PacketFees);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.PacketFees.aminoType, exports.PacketFees.typeUrl);
function createBaseIdentifiedPacketFees() {
    return {
        packetId: channel_1.PacketId.fromPartial({}),
        packetFees: []
    };
}
exports.IdentifiedPacketFees = {
    typeUrl: "/ibc.applications.fee.v1.IdentifiedPacketFees",
    aminoType: "cosmos-sdk/IdentifiedPacketFees",
    is(o) {
        return o && (o.$typeUrl === exports.IdentifiedPacketFees.typeUrl || channel_1.PacketId.is(o.packetId) && Array.isArray(o.packetFees) && (!o.packetFees.length || exports.PacketFee.is(o.packetFees[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.IdentifiedPacketFees.typeUrl || channel_1.PacketId.isAmino(o.packet_id) && Array.isArray(o.packet_fees) && (!o.packet_fees.length || exports.PacketFee.isAmino(o.packet_fees[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.packetId !== undefined) {
            channel_1.PacketId.encode(message.packetId, writer.uint32(10).fork()).ldelim();
        }
        for (const v of message.packetFees) {
            exports.PacketFee.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 = createBaseIdentifiedPacketFees();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.packetId = channel_1.PacketId.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.packetFees.push(exports.PacketFee.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseIdentifiedPacketFees();
        message.packetId = object.packetId !== undefined && object.packetId !== null ? channel_1.PacketId.fromPartial(object.packetId) : undefined;
        message.packetFees = object.packetFees?.map(e => exports.PacketFee.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseIdentifiedPacketFees();
        if (object.packet_id !== undefined && object.packet_id !== null) {
            message.packetId = channel_1.PacketId.fromAmino(object.packet_id);
        }
        message.packetFees = object.packet_fees?.map(e => exports.PacketFee.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.packet_id = message.packetId ? channel_1.PacketId.toAmino(message.packetId) : undefined;
        if (message.packetFees) {
            obj.packet_fees = message.packetFees.map(e => e ? exports.PacketFee.toAmino(e) : undefined);
        }
        else {
            obj.packet_fees = message.packetFees;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.IdentifiedPacketFees.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/IdentifiedPacketFees",
            value: exports.IdentifiedPacketFees.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.IdentifiedPacketFees.decode(message.value);
    },
    toProto(message) {
        return exports.IdentifiedPacketFees.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.fee.v1.IdentifiedPacketFees",
            value: exports.IdentifiedPacketFees.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.IdentifiedPacketFees.typeUrl, exports.IdentifiedPacketFees);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.IdentifiedPacketFees.aminoType, exports.IdentifiedPacketFees.typeUrl);
