using Newtonsoft.Json;
using System;
using WpfApp1;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp1.model
{
    public class JSONDataProvider : LocalDataProvider, IDataProvider
    {
        private List<CarWithStringDates> _CarList;

        public JSONDataProvider()
        {
            using (var sr = new StreamReader("./Test.json"))
            {
                _CarList = JsonConvert.DeserializeObject<CarWithStringDates[]>(sr.ReadToEnd()).ToList();

            }
        }

        public new IEnumerable<cars> getCars()
        {
            return _CarList.Select(p => new cars
            {
                name = p.name,

                year = p.year,

                price = p.price,

                color = p.color,

                defects = p.defects,

                photo = p.photo,

                dateOfLastSTO = p.dateOfLastSTO == null ? null : DateOnly.Parse(p.dateOfLastSTO),
                
            });
        }
    }
}
