using DeviceRepairAndOptimization.Models;
using DeviceRepairAndOptimization.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace DeviceRepairAndOptimization.Data
{
    public class DriveRepairLogsMaintenance
    {
        private static DriveRepairLogsMaintenance manager;

        public static DriveRepairLogsMaintenance Instance
        {
            get
            {
                if (manager == null)
                    manager = new DriveRepairLogsMaintenance();
                return manager;
            }
        }


        /// <summary>
        /// 根据设备编号获取数据
        /// </summary>
        /// <param name="EquipmentID">设备编号</param>
        /// <returns></returns>
        public List<View_DriveRepairLogs> GetDatasByEquipmentID(int EquipmentID)
        {
            List<View_DriveRepairLogs> lst = null;
            try
            {
                if (EquipmentID == 0)
                    return new List<View_DriveRepairLogs>();

                switch (Models.Config.Configurations.Properties.ConnType?.ToLower())
                {
                    case "api":

                        APIResponseData result = ApiHelper.Instance.SendMessage(new CsharpHttpHelper.HttpItem
                        {
                            URL = ServiceRoute.GetDriveRepairLogsByEquipmentAutoID,
                            Method = "Post",
                            ContentType = "application/json; charset=utf-8",//返回类型    可选项有默认值
                            Postdata = JsonConvert.SerializeObject(new { equipmentid = EquipmentID })
                        });

                        if (result.Code == 1)
                        {
                            lst = JsonConvert.DeserializeObject<List<View_DriveRepairLogs>>(result.Data + "");
                        }
                        else
                        {
                            throw new Exception(result.Message);
                        }

                        break;
                    case "sql":

                        DeviceRepairRecordAccess.Instance.GetDatasByEquipmentID(EquipmentID);

                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return lst;
        }
    }
}
