package com.jdblabs.timestamper.core;

import com.jdbernard.util.SmartConfig;
import java.io.File;
import java.net.URI;

/**
 *
 * @author Jonathan Bernard ({@literal jdbernard@gmail.com})
 */
public class TimelineSourceFactory {

    public static TimelineSource newInstance(URI uri, SmartConfig config) {
        // File based
        if ("file".equalsIgnoreCase(uri.getScheme())) {
            return new FileTimelineSource(uri, config);
        }

        // Twitter
        else if ("http".equalsIgnoreCase(uri.getScheme()) &&
                    ("twitter.com".equalsIgnoreCase(uri.getHost())
                  || "www.twitter.com".equalsIgnoreCase(uri.getHost()))) {
            throw new UnsupportedOperationException("Twitter based timeline "
                    + "sources are not yet supported.");
        }

        // Other HTTP, assume JDB Labs web app
        else if ("http".equalsIgnoreCase(uri.getScheme())) {
            return new JDBLabsWebTimelineSource(uri, config);
        }

        // SSH
        else if ("ssh".equalsIgnoreCase(uri.getScheme())) {
            throw new UnsupportedOperationException("SSH based timeline sources"
                    + " are not yet supported.");
        }

        // unknown
        else {
            throw new UnsupportedOperationException("Timeline sources for the"
                    + " " + uri.getScheme() + " are not currently supported.");
        }
    }
}
