using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Lab_Extensibility.ResultWriters
{
    public class CsvResultWriter : IResultWriter
    {
        private readonly string _outputFileName;

        public CsvResultWriter(string outputFileName)
        {
            ArgumentException.ThrowIfNullOrEmpty(outputFileName);
            _outputFileName = outputFileName;
        }

        public void Write(List<Person> persons)
        {
            using (StreamWriter writer = new(_outputFileName))
            {
                foreach (Person p in persons)
                    writer.WriteLine($"{p.FirstName}; {p.LastName}; {p.State}; {p.City}; {p.Age}; {p.Weight}; {p.Decease}");
            }

            Console.WriteLine($"Output file generated ({_outputFileName})");
        }
    }
}
