using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using C1.Chart;
using C1.Xaml.Chart;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace FlexChartExplorer
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Financial : Page
    {
        int npts = 30;
        List<Quote> _data;
        Dictionary<ChartType, string> _chartTypes;
        Random rnd = new Random();

        public Financial()
        {
            this.InitializeComponent();
        }

        public Dictionary<ChartType, string> ChartTypes
        {
            get
            {
                if (_chartTypes == null)
                {
                    _chartTypes = DataCreator.CreateFinancialChartTypes();
                }

                return _chartTypes;
            }
        }

        public Series FinancialSeries
        {
            get
            {
                return financialSeries;
            }
        }

        public List<Quote> Data
        {
            get
            {
                if (_data == null)
                {
                    _data = CreateData();
                }

                return _data;
            }
        }

        List<Quote> CreateData()
        {
            List<Quote> list = new List<Quote>();
            var dt = DateTime.Today;
            for (var i = 0; i < npts; i++)
            {
                var q = new Quote();
                q.Time = dt.AddDays(i);
                if (i > 0)
                    q.Open = list[i - 1].Close;
                else
                    q.Open = 1000;
                q.High = q.Open + rnd.Next(50);
                q.Low = q.Open - rnd.Next(50);
                q.Close = rnd.Next((int)q.Low, (int)q.High);
                q.Volume = rnd.Next(0, 100);
                list.Add(q);
            }

            return list;
        }
    }

    public class Quote
    {
        public DateTime Time { get; set; }

        public double Open { get; set; }
        public double Close { get; set; }
        public double High { get; set; }
        public double Low { get; set; }

        public double Volume { get; set; }
    }
}
