package be.msyben.vinylManager.tools.discogs;

import be.msyben.vinylManager.tools.discogs.entities.FolderReleaseResponse;
import be.msyben.vinylManager.tools.discogs.entities.Inventory;
import be.msyben.vinylManager.tools.discogs.entities.Release;
import be.msyben.vinylManager.tools.discogs.entities.SearchResponse;
import be.msyben.vinylManager.tools.log.VinylManagerLogger;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public final class DiscogsJsonParser {
    private DiscogsJsonParser() {}
    
    public static Inventory getInventory(String json) {
        try {
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            return gson.fromJson(json, Inventory.class); 
        } catch (Exception e) {
            VinylManagerLogger.log("Erreur lors du décodage de l'inventory", e);
            throw e;
        }
    }
    
    public static Release getRelease(String json) {
        try {
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            return gson.fromJson(json, Release.class); 
        } catch (Exception e) {
            VinylManagerLogger.log("Erreur lors du décodage de la release", e);
            throw e;
        }
    }
    
    public static SearchResponse getSearchResponse(String json) {
        try {
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            return gson.fromJson(json, SearchResponse.class); 
        } catch (Exception e) {
            VinylManagerLogger.log("Erreur lors du décodage de la recherche", e);
            throw e;
        }
    }
    
    
    public static FolderReleaseResponse getFolderReleaseResponse(String json) {
        try {
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            return gson.fromJson(json, FolderReleaseResponse.class); 
        } catch (Exception e) {
            VinylManagerLogger.log("Erreur lors du décodage des releases de folder", e);
            throw e;
        }
    }
}
