/*
 * 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 mybank;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 *
 * @author Verde
 */
public class ScriviLeggiFile {
    private static final String PATH_CODICI_FISCALI = "./src/mybank/codiciFiscali.txt";

    private ScriviLeggiFile() {
    }

    public static void salvaCodiceFiscale(String codiceFiscale) throws IOException {
        try (BufferedWriter bw = new BufferedWriter(
                new FileWriter(PATH_CODICI_FISCALI, true))) {
            bw.write(codiceFiscale + "\n");
        } catch (IOException _) {
            throw new IOException("Errore nella scrittura del codice fiscale.");
        }
    }

    public static List<String> leggiCodiciFiscali() throws IOException {
        List<String> codiciFiscali = null;

        File percorsoCodiciFiscali = new File(PATH_CODICI_FISCALI);
        if (percorsoCodiciFiscali.exists()) {
            try (BufferedReader bf = new BufferedReader(
                    new FileReader(PATH_CODICI_FISCALI))) {
                codiciFiscali = bf.readAllLines();
            } catch (IOException _) {
                throw new IOException("Errore nella lettura dei codici fiscali.");
            }
        }

        return codiciFiscali;
    }
}