﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BusinessLogic.Models;
using System.IO;

namespace BusinessLogic.Data
{
    public class DataReader : IDataReader
    {
        private string fileName;


        public DataReader(string file)
        {
            this.fileName = file;
        }

        public IEnumerable<CustomerBetData> GetData()
        {
            var lines = File.ReadAllLines(fileName);

            var data = lines.Skip(1).AsParallel().Select(x =>
            {
                var values = x.Split(',');
                return new CustomerBetData()
                {
                    Customer = Convert.ToInt32(values[0]),
                    Event = Convert.ToInt32(values[1]),
                    Participants = Convert.ToInt32(values[2]),
                    Stake = Convert.ToInt32(values[3]),
                    WinAmount = Convert.ToInt32(values[4])
                };
            });

            return data;
        }
    }
}
