package tech.nevets.jaml.util;

import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.JAML;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;

public class SkinFetcher {

    public static File getSkinImage() {
        try {
            URL imageUrl = new URL("https://minotar.net/armor/body/" + UserUtils.getActiveUser().getUuid().toString() + "/400.png");
            FileUtils.copyURLToFile(imageUrl, new File(JAML.path + "\\data\\skins\\" + UserUtils.getActiveUser().getUuid() + "-rendered.png"));
            return new File(JAML.path + "\\data\\skins\\" + UserUtils.getActiveUser().getUuid() + "-rendered.png");
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void uploadSkinImage(File skin) {
        Map<Object, Object> data = new HashMap<>();
        data.put("username", "abc");
        data.put("password", "123");
        data.put("custom", "secret");
        data.put("ts", System.currentTimeMillis());

//        try {
//            HttpClient client = HttpClient.newHttpClient();
//            HttpRequest request = HttpRequest.newBuilder()
//                    .POST(buildFormDataFromMap(data))
//                    .uri("https://authserver.mojang.com")
//                    .build();
//            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
//
//            String data = response.body();
//        } catch (IOException | InterruptedException e) {
//            e.printStackTrace();
//        }
    }
}
