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

namespace UserControls
{

    public class RecordTableColumn
    {
        public string name;
        public int orderPriority;
        public bool enabled;
        public bool isReadonly;
        public Type type;
        public RecordTableColumn(string name, 
                                 int orderPriority, 
                                 bool enabled, 
                                 bool isReadonly = true,
                                 Type type = null)
        {
            this.name = name;
            this.orderPriority = orderPriority;
            this.enabled = enabled;
            this.isReadonly = isReadonly;
            this.type = type;
        }
    };

    public class RecordTableColumns
    {
        public RecordTableColumns() { _reorder(); }

        private void _reorder()
        {
            List<RecordTableColumn> tmp = new List<RecordTableColumn>();
            SortedSet<int> priorities = new SortedSet<int>(columns.Select(x => x.orderPriority));
            foreach (var prir in priorities.Reverse())
                foreach (var col in columns)
                    if (col.orderPriority == prir)
                        tmp.Add(col);
            columns = tmp;
              
        }

        public List<RecordTableColumn> columns = new List<RecordTableColumn>()
        {  
            new RecordTableColumn("class_name",                   -2, true, false),
            //SampleComputedAttributes
            new RecordTableColumn("DistToMean",                   -1, false,  type:typeof(double?)),
            new RecordTableColumn("Cluster",                      -1, false,  type:typeof(int?)),
            new RecordTableColumn("Mahalonobis",                  -1, false,  type:typeof(double?)),
            new RecordTableColumn("MvnPD",                        -1, false,  type:typeof(double?)),
            //
            new RecordTableColumn("DateTime",                      1, true,  type:typeof(DateTime)),
            //WIMCOLUMNS
            new RecordTableColumn("id",                           0, false),
            new RecordTableColumn("datetime",                     0, false),
            new RecordTableColumn("datetime_local",               0, false),
            new RecordTableColumn("ms",                           0, false),
            new RecordTableColumn("wim",                          0, false),
            new RecordTableColumn("opposite_direction",           0, false),
            new RecordTableColumn("wim_detector_id",              0, false),
            new RecordTableColumn("detection_id",                 0, false),
            new RecordTableColumn("detection_image_id",           0, false),
            new RecordTableColumn("detection_image_id_back",      0, false),
            new RecordTableColumn("time_distance_front_front",    0, false),
            new RecordTableColumn("time_distance_back_front",     0, false),
            new RecordTableColumn("vehicle_class",                0, false),
            new RecordTableColumn("vehicle_class_orig",           0, false),
            new RecordTableColumn("velocity",                     0, false),
            new RecordTableColumn("length",                       0, false,  type:typeof(double)),
            new RecordTableColumn("lp",                           0, false),
            new RecordTableColumn("lp_back",                      0, false),
            new RecordTableColumn("insert_timestamp",             0, false),
            new RecordTableColumn("total_weight",                 0, true,  type:typeof(double)),
            new RecordTableColumn("axles_count",                  0, true,  type:typeof(int)),
            new RecordTableColumn("axles_1_2_base",               0, false, type:typeof(int)),
            new RecordTableColumn("axles_2_3_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axles_3_4_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axles_4_5_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axles_5_6_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axles_6_7_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axles_7_8_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axles_8_9_base",               0, false, type:typeof(double)),
            new RecordTableColumn("axle_1_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_1_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_2_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_2_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_3_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_3_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_4_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_4_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_5_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_5_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_6_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_6_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_7_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_7_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_8_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_8_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("axle_9_leftside_load",         0, false, type:typeof(double)),
            new RecordTableColumn("axle_9_rightside_load",        0, false, type:typeof(double)),
            new RecordTableColumn("overweighting",                0, false),
            new RecordTableColumn("match_datetime",               0, false),
            new RecordTableColumn("loop_class",                   0, false),
            new RecordTableColumn("l_pos",                        0, false),
            new RecordTableColumn("r_pos",                        0, false),
            new RecordTableColumn("dual_tire",                    0, false),
            new RecordTableColumn("validity",                     0, false),
            new RecordTableColumn("validity_flags",               0, false),
            new RecordTableColumn("error_flags",                  0, false),
            new RecordTableColumn("temp_internal",                0, false),
            new RecordTableColumn("temp_asphalt",                 0, false),
            new RecordTableColumn("acceleration",                 0, false),
            new RecordTableColumn("ax_accu_1",                    0, false),
            new RecordTableColumn("ax_accu_2",                    0, false),
            new RecordTableColumn("ax_accu_3",                    0, false),
            new RecordTableColumn("ax_accu_4",                    0, false),
            new RecordTableColumn("ax_accu_5",                    0, false),
            new RecordTableColumn("ax_accu_6",                    0, false),
            new RecordTableColumn("ax_accu_7",                    0, false),
            new RecordTableColumn("ax_accu_8",                    0, false),
            new RecordTableColumn("ax_accu_9",                    0, false),
            new RecordTableColumn("sum_accu",                     0, false),
            new RecordTableColumn("overweight_desc",              0, false),
            new RecordTableColumn("passage_type",                 0, false),
            new RecordTableColumn("unicam_wim_class",             0, false),
            new RecordTableColumn("v_width",                      0, false),
            new RecordTableColumn("width",                        0, false),
            new RecordTableColumn("possition",                    0, false),
            new RecordTableColumn("velocity_loop",                0, false),
            new RecordTableColumn("v_code",                       0, false),
            new RecordTableColumn("vc_raised",                    0, false),
            new RecordTableColumn("e_code",                       0, false),
            new RecordTableColumn("ec_raised",                    0, false),
            new RecordTableColumn("car_layout",                   0, false),
            new RecordTableColumn("stop_go",                      0, false),
            new RecordTableColumn("s_height",                     0, false),
            new RecordTableColumn("s_width",                      0, false),
            new RecordTableColumn("s_length",                     0, false),
            new RecordTableColumn("s_separated",                  0, false),
            new RecordTableColumn("overheight",                   0, false),
            new RecordTableColumn("oversize",                     0, false),
            new RecordTableColumn("oversize_desc",                0, false),
            new RecordTableColumn("overvelocity",                 0, false),
            new RecordTableColumn("overvelocity_desc",            0, false),
            new RecordTableColumn("trailer_presence",             0, false),
            new RecordTableColumn("found_in_whitelist",           0, false),
            new RecordTableColumn("WCF_post_class",               0, false),
            //FRQ Attributes
            new RecordTableColumn("TsPH",                         0, false),
            new RecordTableColumn("TsPL",                         0, false),
            new RecordTableColumn("TsOH",                         0, false),
            new RecordTableColumn("TsOL",                         0, false),
            new RecordTableColumn("Velocity",                     0, false),
            new RecordTableColumn("Shift",                        0, false),
            new RecordTableColumn("Distance",                     0, false),
            new RecordTableColumn("Length",                       0, true, type:typeof(double)),
            new RecordTableColumn("Curvitude",                    0, false, type:typeof(double)),
            new RecordTableColumn("Center",                       0, false, type:typeof(double)),
            new RecordTableColumn("FillF",                        0, false, type:typeof(double)),
            new RecordTableColumn("Curv1",                        0, false, type:typeof(double)),
            new RecordTableColumn("Curv2",                        0, false, type:typeof(double)),
            new RecordTableColumn("NZPD",                         0, false, type:typeof(double)),
            new RecordTableColumn("P00",                          0, false, type:typeof(double)),
            new RecordTableColumn("P01",                          0, false, type:typeof(double)),
            new RecordTableColumn("P02",                          0, false, type:typeof(double)),
            new RecordTableColumn("P03",                          0, false, type:typeof(double)),
            new RecordTableColumn("P04",                          0, false, type:typeof(double)),
            new RecordTableColumn("P05",                          0, false, type:typeof(double)),
            new RecordTableColumn("P06",                          0, false, type:typeof(double)),
            new RecordTableColumn("P07",                          0, false, type:typeof(double)),
            new RecordTableColumn("P08",                          0, false, type:typeof(double)),
            new RecordTableColumn("P09",                          0, false, type:typeof(double)),
            new RecordTableColumn("P10",                          0, false, type:typeof(double)),
            new RecordTableColumn("P11",                          0, false, type:typeof(double)),
            new RecordTableColumn("P12",                          0, false, type:typeof(double)),
            new RecordTableColumn("P13",                          0, false, type:typeof(double)),
            new RecordTableColumn("P14",                          0, false, type:typeof(double)),
            new RecordTableColumn("P15",                          0, false, type:typeof(double)),
            new RecordTableColumn("P16",                          0, false, type:typeof(double)),
            new RecordTableColumn("P17",                          0, false, type:typeof(double)),
            new RecordTableColumn("P18",                          0, false, type:typeof(double)),
            new RecordTableColumn("P19",                          0, false, type:typeof(double)),
            new RecordTableColumn("Pb",                           0, false, type:typeof(int)),
            new RecordTableColumn("Pe",                           0, false, type:typeof(int)),
            new RecordTableColumn("KlasRes",                      0, false),
            new RecordTableColumn("KlT",                          0, false),
            new RecordTableColumn("KlV",                          0, false),
            new RecordTableColumn("WDir",                         0, false),
            new RecordTableColumn("LoopWidth",                    0, false, type:typeof(double)), 
        };

        public RecordTableColumn GetColumn(string name)
        {
            foreach (var col in columns)
                if (col.name == name)
                    return col;
            return null;
        }

    };
}
