"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ForwardedPacket = exports.GenesisState = void 0;
const token_1 = require("./token");
const transfer_1 = require("../v1/transfer");
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 createBaseGenesisState() {
    return {
        portId: "",
        denoms: [],
        params: transfer_1.Params.fromPartial({}),
        totalEscrowed: [],
        forwardedPackets: []
    };
}
exports.GenesisState = {
    typeUrl: "/ibc.applications.transfer.v2.GenesisState",
    aminoType: "cosmos-sdk/GenesisState",
    is(o) {
        return o && (o.$typeUrl === exports.GenesisState.typeUrl || typeof o.portId === "string" && Array.isArray(o.denoms) && (!o.denoms.length || token_1.Denom.is(o.denoms[0])) && transfer_1.Params.is(o.params) && Array.isArray(o.totalEscrowed) && (!o.totalEscrowed.length || coin_1.Coin.is(o.totalEscrowed[0])) && Array.isArray(o.forwardedPackets) && (!o.forwardedPackets.length || exports.ForwardedPacket.is(o.forwardedPackets[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.GenesisState.typeUrl || typeof o.port_id === "string" && Array.isArray(o.denoms) && (!o.denoms.length || token_1.Denom.isAmino(o.denoms[0])) && transfer_1.Params.isAmino(o.params) && Array.isArray(o.total_escrowed) && (!o.total_escrowed.length || coin_1.Coin.isAmino(o.total_escrowed[0])) && Array.isArray(o.forwarded_packets) && (!o.forwarded_packets.length || exports.ForwardedPacket.isAmino(o.forwarded_packets[0])));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.portId !== "") {
            writer.uint32(10).string(message.portId);
        }
        for (const v of message.denoms) {
            token_1.Denom.encode(v, writer.uint32(18).fork()).ldelim();
        }
        if (message.params !== undefined) {
            transfer_1.Params.encode(message.params, writer.uint32(26).fork()).ldelim();
        }
        for (const v of message.totalEscrowed) {
            coin_1.Coin.encode(v, writer.uint32(34).fork()).ldelim();
        }
        for (const v of message.forwardedPackets) {
            exports.ForwardedPacket.encode(v, 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 = createBaseGenesisState();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.portId = reader.string();
                    break;
                case 2:
                    message.denoms.push(token_1.Denom.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.params = transfer_1.Params.decode(reader, reader.uint32());
                    break;
                case 4:
                    message.totalEscrowed.push(coin_1.Coin.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.forwardedPackets.push(exports.ForwardedPacket.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseGenesisState();
        message.portId = object.portId ?? "";
        message.denoms = object.denoms?.map(e => token_1.Denom.fromPartial(e)) || [];
        message.params = object.params !== undefined && object.params !== null ? transfer_1.Params.fromPartial(object.params) : undefined;
        message.totalEscrowed = object.totalEscrowed?.map(e => coin_1.Coin.fromPartial(e)) || [];
        message.forwardedPackets = object.forwardedPackets?.map(e => exports.ForwardedPacket.fromPartial(e)) || [];
        return message;
    },
    fromAmino(object) {
        const message = createBaseGenesisState();
        if (object.port_id !== undefined && object.port_id !== null) {
            message.portId = object.port_id;
        }
        message.denoms = object.denoms?.map(e => token_1.Denom.fromAmino(e)) || [];
        if (object.params !== undefined && object.params !== null) {
            message.params = transfer_1.Params.fromAmino(object.params);
        }
        message.totalEscrowed = object.total_escrowed?.map(e => coin_1.Coin.fromAmino(e)) || [];
        message.forwardedPackets = object.forwarded_packets?.map(e => exports.ForwardedPacket.fromAmino(e)) || [];
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.port_id = message.portId === "" ? undefined : message.portId;
        if (message.denoms) {
            obj.denoms = message.denoms.map(e => e ? token_1.Denom.toAmino(e) : undefined);
        }
        else {
            obj.denoms = message.denoms;
        }
        obj.params = message.params ? transfer_1.Params.toAmino(message.params) : undefined;
        if (message.totalEscrowed) {
            obj.total_escrowed = message.totalEscrowed.map(e => e ? coin_1.Coin.toAmino(e) : undefined);
        }
        else {
            obj.total_escrowed = message.totalEscrowed;
        }
        if (message.forwardedPackets) {
            obj.forwarded_packets = message.forwardedPackets.map(e => e ? exports.ForwardedPacket.toAmino(e) : undefined);
        }
        else {
            obj.forwarded_packets = message.forwardedPackets;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return exports.GenesisState.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/GenesisState",
            value: exports.GenesisState.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.GenesisState.decode(message.value);
    },
    toProto(message) {
        return exports.GenesisState.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.GenesisState",
            value: exports.GenesisState.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.GenesisState.typeUrl, exports.GenesisState);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.GenesisState.aminoType, exports.GenesisState.typeUrl);
function createBaseForwardedPacket() {
    return {
        forwardKey: channel_1.PacketId.fromPartial({}),
        packet: channel_1.Packet.fromPartial({})
    };
}
exports.ForwardedPacket = {
    typeUrl: "/ibc.applications.transfer.v2.ForwardedPacket",
    aminoType: "cosmos-sdk/ForwardedPacket",
    is(o) {
        return o && (o.$typeUrl === exports.ForwardedPacket.typeUrl || channel_1.PacketId.is(o.forwardKey) && channel_1.Packet.is(o.packet));
    },
    isAmino(o) {
        return o && (o.$typeUrl === exports.ForwardedPacket.typeUrl || channel_1.PacketId.isAmino(o.forward_key) && channel_1.Packet.isAmino(o.packet));
    },
    encode(message, writer = binary_1.BinaryWriter.create()) {
        if (message.forwardKey !== undefined) {
            channel_1.PacketId.encode(message.forwardKey, writer.uint32(10).fork()).ldelim();
        }
        if (message.packet !== undefined) {
            channel_1.Packet.encode(message.packet, 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 = createBaseForwardedPacket();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.forwardKey = channel_1.PacketId.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.packet = channel_1.Packet.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseForwardedPacket();
        message.forwardKey = object.forwardKey !== undefined && object.forwardKey !== null ? channel_1.PacketId.fromPartial(object.forwardKey) : undefined;
        message.packet = object.packet !== undefined && object.packet !== null ? channel_1.Packet.fromPartial(object.packet) : undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseForwardedPacket();
        if (object.forward_key !== undefined && object.forward_key !== null) {
            message.forwardKey = channel_1.PacketId.fromAmino(object.forward_key);
        }
        if (object.packet !== undefined && object.packet !== null) {
            message.packet = channel_1.Packet.fromAmino(object.packet);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.forward_key = message.forwardKey ? channel_1.PacketId.toAmino(message.forwardKey) : undefined;
        obj.packet = message.packet ? channel_1.Packet.toAmino(message.packet) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return exports.ForwardedPacket.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/ForwardedPacket",
            value: exports.ForwardedPacket.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return exports.ForwardedPacket.decode(message.value);
    },
    toProto(message) {
        return exports.ForwardedPacket.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.ForwardedPacket",
            value: exports.ForwardedPacket.encode(message).finish()
        };
    }
};
registry_1.GlobalDecoderRegistry.register(exports.ForwardedPacket.typeUrl, exports.ForwardedPacket);
registry_1.GlobalDecoderRegistry.registerAminoProtoMapping(exports.ForwardedPacket.aminoType, exports.ForwardedPacket.typeUrl);
