package de.antco.projekt.importers;

import de.antco.projekt.model.Person;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class CsvPersonImporter implements IImporter<Person> {

    @Override
    public List<Person> importData(String path) throws Exception {
        List<Person> result = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader(path))) {
            String line;
            while ((line = br.readLine()) != null) {
                if (line.isBlank()) continue;
                String[] parts = line.split(";");
                if (parts.length >= 2) {
                    String name = parts[0].trim();
                    String phone = parts[1].trim();
                    String email = parts.length > 2 ? parts[2].trim() : "";
                    String address = parts.length > 3 ? parts[3].trim() : "";
                    // ID 0 as placeholder, will be ignored/regenerated on DB insert
                    result.add(new Person(0, name, phone, email, address));
                }
            }
        }
        return result;
    }
}
