using System.Globalization;
using CsvHelper;
using CsvHelper.Configuration;
using UniversalTagEditor.Types;

namespace UniversalTagEditor.Helpers;

public static class CsvParser
{
    public static TrackInfo[] ParseCsvTable(string path)
    {
        CsvConfiguration config = new(CultureInfo.InvariantCulture)
        {
            Delimiter = "\t"
        };
        using (var reader = new StreamReader(path))
        using (var csv = new CsvReader(reader, config))
        {
            csv.Context.Configuration.Delimiter = "\t";
            csv.Context.RegisterClassMap<TrackInfoMap>();
            
            return csv.GetRecords<TrackInfo>().ToArray();
        }
    }
}