using Foresight;
using Foresight.Fleet.Services.Asset;
using Foresight.Fleet.Services.JobSite;
using Foresight.Fleet.Services.MapView;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IronIntel.Contractor.MapView
{
    public class JobSiteViewItem
    {
        public string CompanyID { get; set; } = "";
        public string CompanyName { get; set; } = "";

        public Int64 ID { get; set; }
        public string Name { get; set; }
        public string[] Types { get; set; }
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public double Radius { get; set; }
        public string Radius_UOM { get; set; }
        public string ContractorID { get; set; }
        public string ColorString { get; set; }
        public IIColor Color { get; set; }
        public string Notes { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime ProjectedEndDate { get; set; }
        public DateTime EndDate { get; set; }
        public PostionItem[] Polygon { get; set; }
        public Int64 BaseOnMachineID { get; set; }
        public string BaseonMachineName { get; set; }
        public string Code { get; set; }
        public long[] Assets { get; set; }
        public bool IsDeleted { get; set; }
        public int RegionId { get; set; }
        public string Region { get; set; }
        public string Number { get; set; }
        public string Foreman { get; set; }
        public string Manager { get; set; }
        public string Phone { get; set; }
        public string Email { get; set; }
        public string Group { get; set; }
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string County { get; set; }

        public string StartDateStr
        {
            get
            {
                if (StartDate == DateTime.MinValue)
                {
                    return "";
                }
                else
                {
                    return StartDate.ToShortDateString();
                }
            }
        }



        public string EndDateStr
        {
            get
            {
                if (EndDate == DateTime.MinValue)
                {
                    return "";
                }
                else
                {
                    return EndDate.ToShortDateString();
                }
            }
        }
        public string ProjectedEndDateStr
        {
            get
            {
                if (ProjectedEndDate == DateTime.MinValue)
                {
                    return "";
                }
                else
                {
                    return ProjectedEndDate.ToShortDateString();
                }
            }
        }

        public string RadiusStr
        {
            get
            {
                if (Radius > 0)
                {
                    return Radius + " " + Radius_UOM + "(s)";
                }
                else
                {
                    return "";
                }
            }
        }

        public JobSiteAssetItem[] Machines { get; set; }
    }

    public class AssetMapViewPinItemClient : AssetMapViewPinItem
    {
        public string CompanyID { get; set; } = "";

        public string CompanyName { get; set; } = "";
    }

    public class AssetGroupViewItem
    {
        public string CompanyID { get; set; } = "";
        public string CompanyName { get; set; } = "";
        public string ID { get; set; }
        public string Name { get; set; }
        public long[] Assets { get; set; }
    }

    public class CompanyLocationViewItem
    {
        public int ID { get; set; }
        public string CompanyID { get; set; } = "";
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public string LocationName { get; set; }
        public string Notes { get; set; }
        public string IconUrl { get; set; }
    }

    public class MapAlertViewDefinitionItem
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public MapAlertLayerDefinitionItem[] Layers { get; set; }
        public List<LookupDataSourceDataItem> LookupDataSources { get; set; } = new List<LookupDataSourceDataItem>();
    }

    public class LookupDataSourceDataItem
    {
        public string ID { get; set; }

        private List<KeyValuePair<string, string>> _Items = new List<KeyValuePair<string, string>>();
        public List<KeyValuePair<string, string>> Items
        {
            get
            {
                return _Items;
            }
        }
        public string Name { get; set; }
    }

    public class MapAlertLayerDefinitionItem
    {
        public string ID { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string IconColor { get; set; }
        public string AlertLayerType { get; set; }//Primary/Secondary
        public string LegendUrl { get; set; }
        public DbQueryParameterItem[] CriteriaSQLParameters { get; set; }
        public DbQueryParameterItem[] AlertSQLParameters { get; set; }
        public AlertLayerPivotViewItem[] Pivots { get; set; }

    }

    public class DbQueryParameterItem
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public string Caption { get; set; }
        public string Description { get; set; }
        public DataTypes DataType { get; set; }
        public string DefaultValue { get; set; }
        public string ParameterValue { get; set; }
        public QueryParameterDisplayStyles DisplayStyle { get; set; }
        public string LookupDatasourceID { get; set; }
        public bool DisplayCaptionField { get; set; }//当参数显示为dropdown时，指示显示Key或者text
        public bool IsField { get; set; }//表明该参数名是一个数据库参数或是结果集的字段，如果是结果集的字段，则该定义必须要与lookupdatasource关联。
        public bool IsAllAllowed { get; set; }
        public bool MutipleSelect { get; set; }
    }

    public class QueryParameterSource
    {
        public string ID { get; set; }
        public string Name { get; set; }
    }

    public class LocationViewItem
    {
        public long LogId { get; set; }
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public DateTime LocationTime { get; set; }
        public string LocationTimeText
        {
            get
            {
                if (LocationTime != DateTime.MinValue)
                {
                    return LocationTime.ToString();
                }
                return "";
            }
        }
        public string DataSource { get; set; }
        public string SubSource { get; set; }
        public string EventType { get; set; } = string.Empty;
        public string MsgUID { get; set; } = string.Empty;

        public double Speed { get; set; } = -1;
        public string SpeedUnit { get; set; }
        public double PostedSpeed { get; set; } = -1;
        public string PostedSpeedUnit { get; set; }
        public string Street { get; set; } = string.Empty;
        public string IconURL { get; set; } = string.Empty;
        public List<KeyValuePair<string, string>> SmartWitnessVideoUrl { get; set; }
        public SpeedingBehaviors SpeedingBehavior { get; set; }
        public HarshDrivingEvents HarshDringEvent { get; set; }
        public bool FromSmartWitness { get; set; }
    }

    public class MachineTypeItem
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }

    public struct PostionItem
    {
        public double Latitude;
        public double Longitude;

        public PostionItem(double latitude, double longitude)
        {
            Latitude = latitude;
            Longitude = longitude;
        }
    }

    public class ShapeFileItem
    {
        public string CompanyID { get; set; } = "";
        public string CompanyName { get; set; } = "";
        public long ID { get; set; }
        public string Name { get; set; }
        public string Notes { get; set; }
        public string FileName { get; set; }
    }
}
