using System.Collections.Generic;
using System.Data;

using BeWo.Data.Entities;

namespace BeWo.Report.ReportObjects
{
    public class QueryRO : AbstractBeWoReportObject<QueryRO>
    {
        private List<Row> _Rows = new List<Row>();

        public DataTable DataTable { get; set; }

        public string Name { get; set; }

        public List<Row> Rows
        {
            get
            {
                return this._Rows;
            }

            set
            {
                this._Rows = value;
            }
        }

        public static QueryRO Create(Query query, DataTable table)
        {
            QueryRO ro = new QueryRO();
            ro.DataTable = table;
            ro.Name = query.Title;

            foreach (DataRow datarow in table.Rows)
            {
                Row row = new Row();

                int index = 1;
                foreach (var item in datarow.ItemArray)
                {
                    switch (index)
                    {
                        case 1:
                            row.Field1 = item;
                            break;
                        case 2:
                            row.Field2 = item;
                            break;
                        case 3:
                            row.Field3 = item;
                            break;
                        case 4:
                            row.Field4 = item;
                            break;
                        case 5:
                            row.Field5 = item;
                            break;
                        case 6:
                            row.Field6 = item;
                            break;
                        case 7:
                            row.Field7 = item;
                            break;
                        case 8:
                            row.Field8 = item;
                            break;
                        case 9:
                            row.Field9 = item;
                            break;
                        case 10:
                            row.Field10 = item;
                            break;
                        case 11:
                            row.Field11 = item;
                            break;
                        case 12:
                            row.Field12 = item;
                            break;
                        case 13:
                            row.Field13 = item;
                            break;
                        case 14:
                            row.Field14 = item;
                            break;
                        case 15:
                            row.Field15 = item;
                            break;
                        case 16:
                            row.Field16 = item;
                            break;
                        case 17:
                            row.Field17 = item;
                            break;
                        case 18:
                            row.Field18 = item;
                            break;
                        case 19:
                            row.Field19 = item;
                            break;
                        case 20:
                            row.Field20 = item;
                            break;

                        default:
                            break;
                    }

                    index++;
                }

                ro.Rows.Add(row);
            }

            return ro;
        }

        public class Row
        {
            public object Field1 { get; set; }

            public object Field10 { get; set; }

            public object Field11 { get; set; }

            public object Field12 { get; set; }

            public object Field13 { get; set; }

            public object Field14 { get; set; }

            public object Field15 { get; set; }

            public object Field16 { get; set; }

            public object Field17 { get; set; }

            public object Field18 { get; set; }

            public object Field19 { get; set; }

            public object Field2 { get; set; }

            public object Field20 { get; set; }

            public object Field3 { get; set; }

            public object Field4 { get; set; }

            public object Field5 { get; set; }

            public object Field6 { get; set; }

            public object Field7 { get; set; }

            public object Field8 { get; set; }

            public object Field9 { get; set; }

            public List<Row> ChildRows1 { get; set; }
            public List<Row> ChildRows2 { get; set; }
            public List<Row> ChildRows3 { get; set; }
        }
    }
}