package net.anomalyxii.bot.discord.server;

import net.anomalyxii.bot.api.server.Protocol;
import net.anomalyxii.bot.api.server.strategies.FormatStrategy;
import net.anomalyxii.bot.api.server.strategies.ParseStrategy;
import sx.blah.discord.api.ClientBuilder;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.api.events.Event;
import sx.blah.discord.util.DiscordException;

/**
 * The {@code IRC} protocol.
 * <p>
 * Created by Anomaly on 06/05/17.
 */
public class DiscordProtocol implements Protocol<Event> {

    private static final DiscordProtocol INSTANCE = new DiscordProtocol();

    // *********************************
    // Constructors
    // *********************************

    private DiscordProtocol() {
    }

    // *********************************
    // Protcol Methods
    // *********************************

    @Override
    public Class<Event> getRawType() {
        return Event.class;
    }

    @Override
    public ParseStrategy<Event> getParseStrategy() {
        throw new UnsupportedOperationException("DiscordProtocol#getParseStrategy requires ProtocolInstance");
    }

    @Override
    public FormatStrategy<Event> getFormatStrategy() {
        throw new UnsupportedOperationException("DiscordProtocol#getFormatStrategy requires ProtocolInstance");
    }

    // *********************************
    // Protocol and Instance Methods
    // *********************************

    /**
     * Get the singleton instance of this {@link Protocol}.
     *
     * @return the instance
     */
    public static DiscordProtocol getInstance() {
        return INSTANCE;
    }

    /**
     * Get the new {@link DiscordProtocolInstance}.
     *
     * @return the instance
     */
    public static DiscordProtocolInstance getProtocolInstance(String token) throws DiscordException {
        ClientBuilder clientBuilder = new ClientBuilder();
        clientBuilder.withToken(token);
        return new DiscordProtocolInstance(clientBuilder.build());
    }

    /**
     * Get the new {@link DiscordProtocolInstance}.
     *
     * @return the instance
     */
    public static DiscordProtocolInstance getProtocolInstance(IDiscordClient client) {
        return new DiscordProtocolInstance(client);
    }

}
