using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using BeWo.Data.Access;
using BeWo.Data.Entities;

using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using BS.Shared;
using BeWo.Service.ServiceImplementations;
using BeWo.Data;

namespace BeWo.Report.ReportObjects
{
    public class JahresReportRO : AbstractBeWoReportObject<JahresReportRO>
	{
        
        public IList<JahresReportTabelle> JahresReportTabelleList { get; set; }

        public class JahresReportTabelle
        {
            public string Name { get; set; }
            public IList<JahresReportDetail> JahresReportDetailList { get; set; }
            //public charControll BarChart{get; set;}

        }

        public class JahresReportDetail
        {
            public string Name { get; set; }

            public int Anzahl { get; set; }

            public int MaennlichAnzahl { get; set; }

            public int WeiblichAnzahl { get; set; }

        }


        public static JahresReportRO Create(int year, long? orgOid, long? teamOid, long? betreuungsartOid)
		{
			var lResult = new JahresReportRO();
            lResult.JahresReportTabelleList = new List<JahresReportTabelle>();
            
            int MaenlichVar; 
            int WeiblichVar; 
            int anzVar;       

            AnalysisServiceImp service = new AnalysisServiceImp();

            DateTime startDate = new DateTime(year, 1, 1);

            var list = service.CreateAnnualReport(orgOid, teamOid, betreuungsartOid, startDate, startDate.AddYears(1));

            foreach (var item in list)
            {
                JahresReportTabelle tabelle = new JahresReportTabelle();
                tabelle.JahresReportDetailList = new List<JahresReportDetail>();
                tabelle.Name = item.Name;
                lResult.JahresReportTabelleList.Add(tabelle);
                
                MaenlichVar = 0;
                WeiblichVar = 0;
                anzVar      = 0;


                foreach (var data in item.Data)
                {
                    JahresReportDetail detail = new JahresReportDetail();
                    detail.Name = data.Name;
                    detail.MaennlichAnzahl = (int)data.Male;
                    //werte
                    MaenlichVar += detail.MaennlichAnzahl;
                    detail.WeiblichAnzahl = (int)data.Female;
                    //wert
                    WeiblichVar += detail.WeiblichAnzahl;
                    detail.Anzahl = data.Value.HasValue ? (int)data.Value : 0;
                    //wert
                    anzVar += detail.Anzahl;
                    tabelle.JahresReportDetailList.Add(detail);
                }
                //--------- Hier muss der BAr chat code hin -----------------------------
                /*ChartControl sideBySideBarChart = new ChartControl();

                // Create the first side-by-side bar series and add points to it.
                Series series1 = new Series("Side-by-Side Bar Series 1", ViewType.Bar);
                series1.Points.Add(new SeriesPoint("Anzahl", new double[] { anzVar }));
                series1.Points.Add(new SeriesPoint("Weiblich", new double[] { WeiblichVar }));
                series1.Points.Add(new SeriesPoint("Männlich", new double[] { MaenlichVar }));

                // Add the series to the chart.
                sideBySideBarChart.Series.Add(series1);

                // Hide the legend (if necessary).
                sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.true;

                // Rotate the diagram (if necessary).
                ((XYDiagram)sideBySideBarChart.Diagram).Rotated = true;

                // Add a title to the chart (if necessary).
                ChartTitle chartTitle1 = new ChartTitle();
                chartTitle1.Text = "Voll was Los";
                sideBySideBarChart.Titles.Add(chartTitle1);

                // Add the chart to the form.
                sideBySideBarChart.Dock = DockStyle.Fill;
                this.Controls.Add(sideBySideBarChart);
                */
                //-----------------------------------------------------------------------
            }
			return lResult;
		}

        //----------------------- Code fÜR EIN BAR Chart Beispiel------------------------------//
        /*
        public void Form1_Load(object sender, EventArgs e) {
            // Create an empty chart.
            ChartControl sideBySideBarChart = new ChartControl();

            // Create the first side-by-side bar series and add points to it.
            Series series1 = new Series("Side-by-Side Bar Series 1", ViewType.Bar);
            series1.Points.Add(new SeriesPoint("A", new double[] { 10 }));
            series1.Points.Add(new SeriesPoint("B", new double[] { 12 }));
            series1.Points.Add(new SeriesPoint("C", new double[] { 14 }));
            series1.Points.Add(new SeriesPoint("D", new double[] { 17 }));

            // Create the second side-by-side bar series and add points to it.
            Series series2 = new Series("Side-by-Side Bar Series 2", ViewType.Bar);
            series2.Points.Add(new SeriesPoint("A", new double[] { 15 }));
            series2.Points.Add(new SeriesPoint("B", new double[] { 18 }));
            series2.Points.Add(new SeriesPoint("C", new double[] { 25 }));
            series2.Points.Add(new SeriesPoint("D", new double[] { 33 }));

            // Add the series to the chart.
            sideBySideBarChart.Series.Add(series1);
            sideBySideBarChart.Series.Add(series2);

            // Hide the legend (if necessary).
            sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;

            // Rotate the diagram (if necessary).
            ((XYDiagram)sideBySideBarChart.Diagram).Rotated = true;

            // Add a title to the chart (if necessary).
            ChartTitle chartTitle1 = new ChartTitle();
            chartTitle1.Text = "Side-by-Side Bar Chart";
            sideBySideBarChart.Titles.Add(chartTitle1);

            // Add the chart to the form.
            sideBySideBarChart.Dock = DockStyle.Fill;
            this.Controls.Add(sideBySideBarChart);
        }
        */
        
    }
}
    