package org.sillyjirafe.uoapi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.sillyjirafe.uoapi.binds.*;

public class Out {
	List<Api> Apis = new ArrayList<>();
	Map<String, Boolean> Succes = new HashMap<>();
	
	public List<String> PreOut()
	{
		Apis.add(new GitHubMITApi());
        Apis.add(new GitHubLGPLApi());
        Apis.add(new GitHubApacheApi());
        Apis.add(new OpenVerseImagesApi());
        Apis.add(new OpenVerseAudiosApi());
        Apis.add(new PixabayImagesApi());    
        
        List<String> bindnames = new ArrayList<>();
        
        for (Api api : Apis)
        {
        	bindnames.add(api.getName());
        }
        
        return bindnames;
	}
	
    public List<element> out(Map<String, Integer> bindpages, Map<String, String> ApiKeys, Map<String, String> Rnds) throws Exception
    {
        List<element> Elements = new ArrayList<>();
        
        
        for (Api api : Apis) {
            try {
            	List<element> currentapi = Caller.CallApi(api, bindpages.get(api.getName()), ApiKeys.get(api.getName()), Rnds.get(api.getName()));
                Elements.addAll(currentapi);
                Succes.put(api.getName(), true);
            } catch (Exception e) {
                System.out.println("Erreur pour " + api.getName() + " : " + e.getMessage());
                Succes.put(api.getName(), false);
            }
        }
        return Elements;
    }
}
