using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlexChartExplorer
{
    class DataCreator
    {
        public delegate double MathActionDouble(double num);
        public delegate double MathActionInt(int num);
        public static DataTable Create(MathActionDouble function, double from, double to, double step)
        {
            var result = new DataTable();

            result.Columns.Add(new DataColumn("XVals", typeof(double)));
            result.Columns.Add(new DataColumn("YVals", typeof(double)));

            var count = (to - from) / step;

            for (double r = from; r < to; r += step)
            {
                DataRow dr = result.NewRow();
                dr[0] = r;
                dr[1] = function(r);
                result.Rows.Add(dr);
            }
            return result;
        }
        public static DataTable Create(MathActionInt function, int from, int to, int step)
        {
            var result = new DataTable();

            result.Columns.Add(new DataColumn("XVals", typeof(int)));
            result.Columns.Add(new DataColumn("YVals", typeof(int)));

            var count = (to - from) / step;

            for (int r = from; r < to; r += step)
            {
                DataRow dr = result.NewRow();
                dr[0] = r;
                dr[1] = function(r);
                result.Rows.Add(dr);
            }
            return result;
        }
        public static DataTable Create(MathActionDouble functionX, MathActionDouble functionY, int ptsCount)
        {
            var result = new DataTable();

            result.Columns.Add(new DataColumn("XVals", typeof(double)));
            result.Columns.Add(new DataColumn("YVals", typeof(double)));

            for (double i = 0; i < ptsCount; i++)
            {
                DataRow dr = result.NewRow();
                dr[0] = functionX(i);
                dr[1] = functionY(i);
                result.Rows.Add(dr);
            }
            return result;
        }

        public static List<ClassScore> CreateForBoxWhisker()
        {
            var result = new List<ClassScore>();
            result.Add(new ClassScore() { ClassName = "English", SchoolA = 46, SchoolB = 53, SchoolC = 66 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 61, SchoolB = 55, SchoolC = 65 });
            result.Add(new ClassScore() { ClassName = "English", SchoolA = 58, SchoolB = 56, SchoolC = 67 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 58, SchoolB = 51, SchoolC = 64 });
            result.Add(new ClassScore() { ClassName = "English", SchoolA = 63, SchoolB = 53, SchoolC = 45 });
            result.Add(new ClassScore() { ClassName = "English", SchoolA = 63, SchoolB = 50, SchoolC = 65 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 60, SchoolB = 45, SchoolC = 67 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 62, SchoolB = 53, SchoolC = 66 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 63, SchoolB = 54, SchoolC = 64 });
            result.Add(new ClassScore() { ClassName = "English", SchoolA = 63, SchoolB = 52, SchoolC = 67 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 69, SchoolB = 66, SchoolC = 71 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 48, SchoolB = 67, SchoolC = 50 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 54, SchoolB = 50, SchoolC = 56 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 60, SchoolB = 56, SchoolC = 64 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 71, SchoolB = 65, SchoolC = 50 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 48, SchoolB = 70, SchoolC = 72 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 53, SchoolB = 40, SchoolC = 80 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 60, SchoolB = 56, SchoolC = 67 });
            result.Add(new ClassScore() { ClassName = "Math", SchoolA = 61, SchoolB = 56, SchoolC = 45 });
            result.Add(new ClassScore() { ClassName = "English", SchoolA = 63, SchoolB = 58, SchoolC = 64 });
            result.Add(new ClassScore() { ClassName = "Physics", SchoolA = 59, SchoolB = 54, SchoolC = 65 });

            return result;
        }

        public static PlotAreasSampleDataItem[] CreateForPlotAreas()
        {
            var data = new PlotAreasSampleDataItem[20];
            for (int i = 0; i < 20; i++)
            {
                var ac = i;
                var ve = ac * i;
                var di = 0.5 * ac * i * i;
                data[i] = new PlotAreasSampleDataItem()
                {
                    Acceleration = ac,
                    Velocity = ve,
                    Distance = di,
                    Time = i
                };
            }

            return data;
        }

        public static FruitDataItem[] CreateFruit()
        {
            var fruits = new string[] { "Oranges", "Apples", "Pears", "Bananas" };
            var count = fruits.Length;
            var result = new FruitDataItem[count];
            var rnd = new Random();
            for (var i = 0; i < count; i++)
                result[i] = new FruitDataItem()
                {
                    Fruit = fruits[i],
                    March = rnd.Next(20),
                    April = rnd.Next(20),
                    May = rnd.Next(20),
                };
            return result;
        }

        public static Sale[] CreateSales()
        {
            var countries = new string[] { "US", "Germany", "UK", "Japan", "Italy", "Greece", "China", "France", "Russia" };
            var count = countries.Length;
            var result = new Sale[count];
            var rnd = new Random();
            for (int i = 0; i < count; i++)
            {
                result[i] = new Sale()
                {
                    Country = countries[i],
                    Sales = rnd.Next(60)
                };
            }

            return result;
        }
    }
    public class FruitDataItem
    {
        public string Fruit { get; set; }
        public double March { get; set; }
        public double April { get; set; }
        public double May { get; set; }
    }

    public class Sale
    {
        public string Country { get; set; }
        public int Sales { get; set; }
    }

    public class ClassScore
    {
        public string ClassName { get; set; }
        public double SchoolA { get; set; }
        public double SchoolB { get; set; }
        public double SchoolC { get; set; }
    }

    public class PlotAreasSampleDataItem
    {
        public double Acceleration { get; set; }
        public double Velocity { get; set; }
        public double Distance { get; set; }
        public int Time { get; set; }
    }
}
