package ctbrec.ui.sites.streamate;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ctbrec.recorder.Recorder;
import ctbrec.sites.streamate.Streamate;
import ctbrec.ui.tabs.TabProvider;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.scene.Scene;
import javafx.scene.control.Tab;

public class StreamateTabProvider extends TabProvider {
    private static final Logger LOG = LoggerFactory.getLogger(StreamateTabProvider.class);
    private Streamate streamate;
    private Recorder recorder;
    private ThumbOverviewTab followedTab;

    public StreamateTabProvider(Streamate streamate) {
        this.streamate = streamate;
        this.recorder = streamate.getRecorder();
    }

    @Override
    public List<Tab> getTabs(Scene scene) {
        List<Tab> tabs = new ArrayList<>();
        try {
            //                                          performers?domain=streamate.com&from=0&size=48&useProductScore=false&filters=gender:f,ff,mf,tm2f,g;online:true&boostedFilters=&excludedFilters=&country=DE&language=de&genderSetting=f
            //https://member.naiadsystems.com/search/v3/performers?domain=streamate.com&filters=gender:f;online:true&from=0&size=48
            tabs.add(createTab("Girls",         Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:f;online:true"));
            tabs.add(createTab("Guys",          Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:m;online:true"));
            tabs.add(createTab("Couples",       Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:mf;online:true"));
            tabs.add(createTab("Lesbian",       Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:ff;online:true"));
            tabs.add(createTab("Gay",           Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:mm;online:true"));
            tabs.add(createTab("Groups",        Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:g;online:true"));
            tabs.add(createTab("Trans female",  Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:tm2f;online:true"));
            tabs.add(createTab("Trans male",    Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=gender:tf2m;online:true"));
            tabs.add(createTab("New",           Streamate.NAIAD_URL + "/performers?domain=streamate.com&boostedFilters=&excludedFilters=&useProductScore=false&filters=new:true;online:true"));

            followedTab = new StreamateFollowedTab(streamate);
            followedTab.setRecorder(recorder);
            tabs.add(followedTab);
        } catch (IOException e) {
            LOG.error("Couldn't create streamate tab", e);
        }
        return tabs;
    }

    @Override
    public Tab getFollowedTab() {
        return followedTab;
    }

    private Tab createTab(String title, String url) throws IOException {
        StreamateUpdateService updateService = new StreamateUpdateService(streamate, url);
        ThumbOverviewTab tab = new ThumbOverviewTab(title, updateService, streamate);
        tab.setRecorder(recorder);
        return tab;
    }
}
