using Foresight.Fleet.Services.AssetHealth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IronIntel.Contractor.Maintenance
{
    public class AlertInfo
    {
        public long AlertID { get; set; }
        public long WorkOrderID { get; set; }
        public string WorkOrderStatus { get; set; }
        public string AlertType { get; set; }
        public DateTime AlertTime_UTC { get; set; }
        public string AlertTime_UTCStr { get { return AlertTime_UTC == DateTime.MinValue ? "" : AlertTime_UTC.ToString(); } }
        public bool Completed { get; set; }
        public long MachineID { get; set; }
        public int ModelID { get; set; }
        public string Model { get; set; }
        public int MakeID { get; set; }
        public string Make { get; set; }
        public string VIN { get; set; }
        public string MachineName { get; set; }

        private double _EngineHours;
        public double EngineHours
        {
            get
            {
                return _EngineHours;
            }
            set
            {
                value = value > 0 ? value : 0;
                _EngineHours = Math.Round(value, 2);
            }
        }
        private double _CurrentHours;
        public double CurrentHours
        {
            get
            {
                return _CurrentHours;
            }
            set
            {
                value = value > 0 ? value : 0;
                _CurrentHours = Math.Round(value, 2);
            }
        }
        public string Description { get; set; }
        public string ServiceDescription { get; set; }
        public int AlertCount { get; set; }
        public List<long> RepeatedAlerts { get; set; }
        public int OpenWorkOrderCount { get; set; }//针对Alert对应的机器
        public string PMType { get; set; }
        public string AcknowledgedBy { get; set; }
        public string AcknowledgedByName { get; set; }
        public DateTime AcknowledgedTime_UTC { get; set; }
        public string AcknowledgedTime_UTCStr { get { return AcknowledgedTime_UTC == DateTime.MinValue ? "" : AcknowledgedTime_UTC.ToString(); } }
        public string AcknowledgedComment { get; set; }
    }

    public class MachineInfoForAlert
    {
        public long MachineID { get; set; }
        public string VIN { get; set; }
        public string MachineName { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }

        private double _EngineHours;
        public double EngineHours
        {
            get
            {
                return _EngineHours;
            }
            set
            {
                value = value > 0 ? value : 0;
                _EngineHours = Math.Round(value, 2);
            }
        }
        public int DTCAlertCount { get; set; }
        public int PMAlertCount { get; set; }
        public int InspectAlertCount { get; set; }
        public int OpenWorkOrders { get; set; }
        public DateTime LatestAlertDateTime { get; set; }
        public string LatestAlertDateTimeStr { get { return LatestAlertDateTime == DateTime.MinValue ? "" : LatestAlertDateTime.ToString(); } }

        public List<AlertInfo> Alerts { get; } = new List<AlertInfo>();
    }

    public class AssetAlertInfo
    {
        public long ID { get; set; }
        public DateTime AlertTime { get; set; }
        public string AlertTimeStr { get { return AlertTime == DateTime.MinValue ? "" : AlertTime.ToString(); } }
        public string AlertType { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public long AssetID { get; set; }
        public string VIN { get; set; }
        public string AssetName { get; set; }
        public string ModelName { get; set; }
        public string MakeName { get; set; }
        public string AssetTypeName { get; set; }

        private double _EngineHours;
        public double EngineHours
        {
            get
            {
                return _EngineHours;
            }
            set
            {
                value = value > 0 ? value : 0;
                _EngineHours = Math.Round(value, 2);
            }
        }
        public bool Completed { get; set; }
        public DateTime? CompletedDate { get; set; }
        public string CompletedDateStr { get { return CompletedDate == null ? "" : CompletedDate.ToString(); } }

        public AssetAlertCategory Category { get; set; }
    }
}
