import { Denom } from "./token";
import { Params } from "../v1/transfer";
import { Coin } from "../../../../cosmos/base/v1beta1/coin";
import { PacketId, Packet } from "../../../core/channel/v1/channel";
import { BinaryReader, BinaryWriter } from "../../../../binary";
import { GlobalDecoderRegistry } from "../../../../registry";
function createBaseGenesisState() {
    return {
        portId: "",
        denoms: [],
        params: Params.fromPartial({}),
        totalEscrowed: [],
        forwardedPackets: []
    };
}
export const GenesisState = {
    typeUrl: "/ibc.applications.transfer.v2.GenesisState",
    aminoType: "cosmos-sdk/GenesisState",
    is(o) {
        return o && (o.$typeUrl === GenesisState.typeUrl || typeof o.portId === "string" && Array.isArray(o.denoms) && (!o.denoms.length || Denom.is(o.denoms[0])) && Params.is(o.params) && Array.isArray(o.totalEscrowed) && (!o.totalEscrowed.length || Coin.is(o.totalEscrowed[0])) && Array.isArray(o.forwardedPackets) && (!o.forwardedPackets.length || ForwardedPacket.is(o.forwardedPackets[0])));
    },
    isAmino(o) {
        return o && (o.$typeUrl === GenesisState.typeUrl || typeof o.port_id === "string" && Array.isArray(o.denoms) && (!o.denoms.length || Denom.isAmino(o.denoms[0])) && Params.isAmino(o.params) && Array.isArray(o.total_escrowed) && (!o.total_escrowed.length || Coin.isAmino(o.total_escrowed[0])) && Array.isArray(o.forwarded_packets) && (!o.forwarded_packets.length || ForwardedPacket.isAmino(o.forwarded_packets[0])));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.portId !== "") {
            writer.uint32(10).string(message.portId);
        }
        for (const v of message.denoms) {
            Denom.encode(v, writer.uint32(18).fork()).ldelim();
        }
        if (message.params !== undefined) {
            Params.encode(message.params, writer.uint32(26).fork()).ldelim();
        }
        for (const v of message.totalEscrowed) {
            Coin.encode(v, writer.uint32(34).fork()).ldelim();
        }
        for (const v of message.forwardedPackets) {
            ForwardedPacket.encode(v, writer.uint32(42).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new 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(Denom.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.params = Params.decode(reader, reader.uint32());
                    break;
                case 4:
                    message.totalEscrowed.push(Coin.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.forwardedPackets.push(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 => Denom.fromPartial(e)) || [];
        message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
        message.totalEscrowed = object.totalEscrowed?.map(e => Coin.fromPartial(e)) || [];
        message.forwardedPackets = object.forwardedPackets?.map(e => 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 => Denom.fromAmino(e)) || [];
        if (object.params !== undefined && object.params !== null) {
            message.params = Params.fromAmino(object.params);
        }
        message.totalEscrowed = object.total_escrowed?.map(e => Coin.fromAmino(e)) || [];
        message.forwardedPackets = object.forwarded_packets?.map(e => 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 ? Denom.toAmino(e) : undefined);
        }
        else {
            obj.denoms = message.denoms;
        }
        obj.params = message.params ? Params.toAmino(message.params) : undefined;
        if (message.totalEscrowed) {
            obj.total_escrowed = message.totalEscrowed.map(e => e ? Coin.toAmino(e) : undefined);
        }
        else {
            obj.total_escrowed = message.totalEscrowed;
        }
        if (message.forwardedPackets) {
            obj.forwarded_packets = message.forwardedPackets.map(e => e ? ForwardedPacket.toAmino(e) : undefined);
        }
        else {
            obj.forwarded_packets = message.forwardedPackets;
        }
        return obj;
    },
    fromAminoMsg(object) {
        return GenesisState.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/GenesisState",
            value: GenesisState.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return GenesisState.decode(message.value);
    },
    toProto(message) {
        return GenesisState.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.GenesisState",
            value: GenesisState.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(GenesisState.typeUrl, GenesisState);
GlobalDecoderRegistry.registerAminoProtoMapping(GenesisState.aminoType, GenesisState.typeUrl);
function createBaseForwardedPacket() {
    return {
        forwardKey: PacketId.fromPartial({}),
        packet: Packet.fromPartial({})
    };
}
export const ForwardedPacket = {
    typeUrl: "/ibc.applications.transfer.v2.ForwardedPacket",
    aminoType: "cosmos-sdk/ForwardedPacket",
    is(o) {
        return o && (o.$typeUrl === ForwardedPacket.typeUrl || PacketId.is(o.forwardKey) && Packet.is(o.packet));
    },
    isAmino(o) {
        return o && (o.$typeUrl === ForwardedPacket.typeUrl || PacketId.isAmino(o.forward_key) && Packet.isAmino(o.packet));
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.forwardKey !== undefined) {
            PacketId.encode(message.forwardKey, writer.uint32(10).fork()).ldelim();
        }
        if (message.packet !== undefined) {
            Packet.encode(message.packet, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new 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 = PacketId.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.packet = 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 ? PacketId.fromPartial(object.forwardKey) : undefined;
        message.packet = object.packet !== undefined && object.packet !== null ? Packet.fromPartial(object.packet) : undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseForwardedPacket();
        if (object.forward_key !== undefined && object.forward_key !== null) {
            message.forwardKey = PacketId.fromAmino(object.forward_key);
        }
        if (object.packet !== undefined && object.packet !== null) {
            message.packet = Packet.fromAmino(object.packet);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.forward_key = message.forwardKey ? PacketId.toAmino(message.forwardKey) : undefined;
        obj.packet = message.packet ? Packet.toAmino(message.packet) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return ForwardedPacket.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/ForwardedPacket",
            value: ForwardedPacket.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return ForwardedPacket.decode(message.value);
    },
    toProto(message) {
        return ForwardedPacket.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/ibc.applications.transfer.v2.ForwardedPacket",
            value: ForwardedPacket.encode(message).finish()
        };
    }
};
GlobalDecoderRegistry.register(ForwardedPacket.typeUrl, ForwardedPacket);
GlobalDecoderRegistry.registerAminoProtoMapping(ForwardedPacket.aminoType, ForwardedPacket.typeUrl);
