/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package utiles;
// We import the necessary classes: `java.io.BufferedReader`
import java.io.BufferedReader;
// We import the class: `java.io.FileReader` here to use fileReader
import java.io.FileReader;
// We import the class: `java.io.IOException` here to handle  fileReader exception
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author emile.lalorcey
 */
public class ParserJsToSQL {
    
    public ArrayList<ArrayList<String>> lecteurFichier(String cheminAcces){
        ArrayList<ArrayList<String>> donnees = new ArrayList<ArrayList<String>>();
        
        try (FileReader fileReader = new FileReader(cheminAcces);
             BufferedReader bufferedReader = new BufferedReader(fileReader)) {
            String line;
            bufferedReader.readLine();
            while ((line = bufferedReader.readLine()) != null) {
                line = bufferedReader.readLine();
                //récupération de ce qu'il y a entre 2 accolades
                String[] tab = line.split("\\{"); 
                String k = tab[1].split("\\}")[0];

                String[] infos = k.split(",");
                ArrayList<String> valeurs = new ArrayList<String>(); //Liste final des information de la ligne
                for (int j = 0; j<infos.length; j++){
                    String[] cleVal = infos[j].split(": ");
                    valeurs.add(cleVal[1]);
                }
                donnees.add(valeurs);
            }
        } catch (IOException e) {
            System.out.println("Error reading file: " + e.getMessage());
        }
        return donnees;
    }
    
    public void villeInsertion(ArrayList<ArrayList<String>> tabVille){
        String requeteSQL = "Insert into Villes(villeNom,villeX,villeY)"
                +           "Values (?,?,?);";
    }
    
    
    public static void main(String[] args){
        new ParserJsToSQL().lecteurFichier("./svelte/src/plateau_data.js");
    }
    
    
}
