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

namespace IronIntel.Contractor.Maintenance
{

    public class PmScheduleInfo
    {
        public string PmScheduleID { get; set; }
        public string PmScheduleName { get; set; }
        public string PmScheduleUom { get; set; }

        public string PmScheduleType { get; set; } //PM,TBM,HM
        public string Notes { get; set; }

        public PmIntervalItem[] Intervals { get; set; }
        public int[] AllIntervals { get; set; }
    }

    public class PmIntervalItem
    {
        public string PmIntervalID { get; set; }
        public string ScheduleId { get; set; }
        public int Interval { get; set; }
        public int NotificationPeriod { get; set; }

        public string ServiceName { get; set; }
        public bool Recurring { get; set; }
        public int Priority { get; set; }

        public string ServiceDescription { get; set; }
    }

    public class MaintenanceLogInfo
    {
        public string MaintenanceID { get; set; }
        public long MachineID { get; set; }
        public string MachinePin { get; set; }
        public string MachineName { get; set; }
        public string MachineName2 { get; set; }
        public DateTime MaintenanceDate { get; set; }
        public double MaintenanceHours { get; set; }
        public string MachineMake { get; set; }
        public string MachineModel { get; set; }
        public string MachineType { get; set; }

        private double _EngineHours;
        public double EngineHours
        {
            get
            {
                return _EngineHours;
            }
            set
            {
                value = value > 0 ? value : 0;
                _EngineHours = Math.Round(value, 2);
            }
        }
        public string Notes { get; set; }
        public long AlertID { get; set; }

        private double _ODOMeter;
        public double ODOMeter
        {
            get
            {
                return _ODOMeter;
            }
            set
            {
                value = value > 0 ? value : 0;
                _ODOMeter = Math.Round(value, 2);
            }
        }
        public string ODOMemterUOM { get; set; }
        public string LogType { get; set; }

        public string AlertTitle { get; set; }
        public string AlertType { get; set; }
        public DateTime AlertTime { get; set; }

        public string StrForMaintenanceDate { get { return MaintenanceDate.ToShortDateString(); } }

        public string StrForAlertTime
        {
            get
            {
                if (AlertTime != DateTime.MinValue)
                {
                    return AlertTime.ToString("yyyy-MM-dd HH:mm:ss");
                }
                return "";
            }
        }

        public double Cost { get; set; }
        public string InvoiceNumber { get; set; }
        public bool Completed { get; set; }
        public string CompletedByName { get; set; }
        public bool HasAttachment { get; set; }

        public string[] AttachmentIDs { get; set; }//用于保存
        public string ShowName
        {
            get
            {
                //Name取值顺序为Name2,Name,VIN,ID用于前端显示
                string name = MachineName2;
                if (string.IsNullOrWhiteSpace(name))
                    name = MachineName;
                if (string.IsNullOrWhiteSpace(name))
                    name = MachinePin;
                if (string.IsNullOrWhiteSpace(name))
                    name = MachineID.ToString();
                return name;
            }
        }
    }


    public class MaintenanceMachineInfo
    {
        public long MachineID { get; set; }
        public string VIN { get; set; }
        public string MachineName { get; set; }
        public string MachineName2 { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }
        public int TypeID { get; set; }
        public string MachineType { get; set; }

        private double _EngineHours;
        public double EngineHours
        {
            get
            {
                return _EngineHours;
            }
            set
            {
                value = value > 0 ? value : 0;
                _EngineHours = Math.Round(value, 2);
            }
        }
        public DateTime StartDate { get; set; }
        public double StartHours { get; set; }
        public string StartDateString
        {
            get
            {
                if (StartDate == DateTime.MinValue)
                    return "";
                else
                    return StartDate.ToShortDateString();
            }
        }
        public string ShowName
        {
            get
            {
                //Name取值顺序为Name2,Name,VIN,ID用于前端显示
                string name = MachineName2;
                if (string.IsNullOrWhiteSpace(name))
                    name = MachineName;
                if (string.IsNullOrWhiteSpace(name))
                    name = VIN;
                if (string.IsNullOrWhiteSpace(name))
                    name = MachineID.ToString();
                return name;
            }
        }

        private double _Odometer;
        public double Odometer
        {
            get
            {
                return _Odometer;
            }
            set
            {
                value = value > 0 ? value : 0;
                _Odometer = Math.Round(value, 2);
            }
        }

        public double StartOdometer { get; set; }
        public bool Hide { get; set; }
    }

    public class PMAlert
    {
        public string LogID { get; set; }
        public string AlertID { get; set; }
        public string AlertTitle { get; set; }
        public string AlertTime { get; set; }

    }

    public class PMAssetAlertInfo
    {
        public string PmScheduleID { get; set; }
        public string PmIntervalId { get; set; }
        public string ServiceName { get; set; }
        public DateTime? LastAlertTime { get; set; }
        public long AssetId { get; set; }
        public DateTime? StartDate { get; set; }
        public double? StartHours { get; set; }
        public double? StartOdometer { get; set; }
        public int? StartIntervalValue { get; set; }
        public bool Selected { get; set; }
        public int UnMaintainedAlert { get; set; }


        public string PmScheduleName { get; set; }
        public string PmScheduleUom { get; set; }
        public string PmScheduleType { get; set; }
        public string Notes { get; set; }
        public PmIntervalItem[] Intervals { get; set; }
        public int[] AllIntervals { get; set; }

        public string StartDateString
        {
            get
            {
                if (StartDate == null)
                    return "";
                else
                    return StartDate.Value.ToString("MM/dd/yyyy");
            }
        }
        public string LastAlertTimeString
        {
            get
            {
                if (LastAlertTime == null)
                    return "";
                else
                    return LastAlertTime.Value.ToString("MM/dd/yyyy");
            }
        }
    }
}