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

namespace IronIntel.Contractor.Machines
{
    public class MachineRentalInfo
    {
        public long RentalID { get; set; }
        public long MachineID { get; set; }
        public string MachineName { get; set; }
        public string VIN { get; set; }
        public string AquisitionType { get; set; }
        public string AssetID { get; set; }
        public string Division { get; set; }
        public string EQClass { get; set; }
        public string Outside { get; set; }
        public string Description { get; set; }
        public string Vendor { get; set; }
        public int Term { get; set; }
        public string TermUnit { get; set; }
        public decimal RentalRate { get; set; }
        public DateTime? RentalDate { get; set; }
        public string RentalDateStr { get { return RentalDate == null ? "" : RentalDate.Value.ToShortDateString(); } }
        public DateTime? ProjectReturnDate { get; set; }
        public string ProjectReturnDateStr { get { return ProjectReturnDate == null ? "" : ProjectReturnDate.Value.ToShortDateString(); } }
        public DateTime? ReturnDate { get; set; }
        public string ReturnDateStr { get { return ReturnDate == null ? "" : ReturnDate.Value.ToShortDateString(); } }
        public string PONumber { get; set; }
        public string Comments { get; set; }
        public double InsuredValue { get; set; }

        public DateTime? RentalTermBillingDate { get; set; }
        public string RentalTermBillingDateStr { get { return RentalTermBillingDate == null ? "" : RentalTermBillingDate.Value.ToShortDateString(); } }
        public int BillingCycleDays { get; set; }

        public bool Selected { get; set; }
        public bool Hide { get; set; }

        public string DisplayName
        {
            get
            {
                //Name取值顺序为Name2,Name,VIN,ID用于前端显示
                string name = MachineName;
                if (string.IsNullOrWhiteSpace(name))
                    name = VIN;
                if (string.IsNullOrWhiteSpace(name))
                    name = MachineID.ToString();
                return name;
            }
        }

        public string RentalStatus
        {
            get
            {
                //5.Can we add a rental status to Rental Information section:
                //a.Rental Information:  ON RENT(if we are past the Start Date and the return date is blank or a future date and the Proj Return Date is blank or today or greater)
                //b.Rental Information:  OVERDUE(if we are past the Start Date and the Proj Return Date is past and Return Date is Blank)
                //c.Rental Information: RETURNED(if Return Date is populated today or less).

                DateTime today = DateTime.Now.Date;
                if (RentalDate < today
                    && (ReturnDate == null || ReturnDate > today)
                    && (ProjectReturnDate == null || ProjectReturnDate >= today))
                    return "ON RENT";
                if (RentalDate < today
                    && (ProjectReturnDate != null && ProjectReturnDate < today)
                    && ReturnDate == null)
                    return "OVERDUE";
                if (ReturnDate <= today)
                    return "RETURNED";
                return "";
            }
        }

    }

    public class RentalChangeHistoryInfo : MachineRentalInfo
    {
        public string OperateType { get; set; }
        public string LastUpdateUserName { get; set; }
        public string LastUpdatedBy { get; set; }
        public DateTime? LastUpdateDate { get; set; }
        public string LastUpdateDateStr { get { return LastUpdateDate == null ? "" : LastUpdateDate.Value.ToString("M/d/yyyy h:mm tt"); } }

    }
}
