using CsvHelper;
using SnykRestApi.Models;
using SnykRestApi.Models.Parsed;
using System.Globalization;

namespace SnykRestApi.Repositories
{
    public class CsvRepository 
    {
        private readonly Settings _settings;

        public CsvRepository(Settings settings)
        {
            _settings = settings;
        }

        public async Task WriteAll (List<AuditLog> log)
        {
            var t = DateTime.Now;
            var fileName = $"{_settings.CsvFolder}SnykAuditLog_{t:yyyy}{t:MM}{t:dd}_{t:HH}{t:mm}{t:ss}_{t:FFF}.csv";

            using (var writer = new StreamWriter(fileName))
            using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
            {
                await csv.WriteRecordsAsync(log);
            }



        }
    }
}
