using Newtonsoft.Json;
using System;

namespace TsSFCDeivceClient.Model.DeviceWarrantyRequest
{
    public class DeviceWarrantyRequestFormFilter
    {
        /// <summary>
        /// 设备编号
        /// </summary>
        public string EquipmentID { get; set; }

        /// <summary>
        /// 停机单状态
        /// </summary>
        public DeviceWarrantyRequestFormStatus Status { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 设备停机状态
        /// </summary>
        public DeviceRunningStatus DownStatus { get; set; } = DeviceRunningStatus.All;


        public APIResponseData ValidateTime()
        {
            APIResponseData apiResponseData = new APIResponseData { Code = 1 };

            if (StartTime.HasValue && EndTime.HasValue)
            {
                // 结束日期的时间改为当天23：59：59
                EndTime = EndTime.Value.AddDays(1).AddMilliseconds(-1);

                if (StartTime.Value.Date > EndTime.Value.Date)
                {
                    apiResponseData.Code = -1;
                    apiResponseData.Message = $"查询开始时间不允许大于开始结束时间！";
                }
            }

            return apiResponseData;
        }

        public string ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }
    }
}
