package de.jeyp91.gists;

import com.google.api.client.util.DateTime;
import de.jeyp91.apifootball.APIFootballConnector;
import de.jeyp91.apifootball.APIFootballUpdater;
import org.json.simple.JSONArray;
import org.junit.Test;

import java.io.UnsupportedEncodingException;

public class GistProviderTest {

    @Test
    public void listAllGistsTest() {
        GistProvider prov = GistProvider.getInstance();
        JSONArray gists = prov.listAllGists();
        System.out.println(gists);
    }

    @Test
    public void getFileTest() {
        GistProvider prov = GistProvider.getInstance();
        String id = prov.getGistID("Team_ID_Matcher");
        String file = prov.getFileFromGist(id,"Team_ID_Matcher.json");
        System.out.println(file);
    }

    @Test
    public void getTeamIdMatcherTest() {
        GistProvider prov = GistProvider.getInstance();
        JSONArray matcher = prov.getTeamIdMatcher();
        System.out.println(matcher);
    }

    @Test
    public void getGistUpdatedTimestampTest() {
        GistProvider prov = GistProvider.getInstance();
        DateTime date = prov.getGistUpdatedTimestamp("Matches");
        System.out.println(date);
    }

    @Test
    public void getGistIDTest() {
        GistProvider prov = GistProvider.getInstance();
        String id = prov.getGistID("Matches");
        System.out.println(id);
    }

    @Test
    public void updateGistTest() throws UnsupportedEncodingException {
        GistProvider prov = GistProvider.getInstance();
        APIFootballUpdater updater = new APIFootballUpdater(2021);
        String body = updater.getRawData("https://v2.api-football.com/fixtures/league/2738?timezone=Europe/Berlin");
        String content = prov.updateGist("6ec51d59cac70c9f4c040eeea1c0cdd9", "matches_league_2738.json", body);
        System.out.println(content);
    }
}
