using CsharpHttpHelper;
using DeviceRepairAndOptimization.Models;
using DeviceRepairAndOptimization.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceRepairAndOptimization.Business
{
    public class MaintenanceRecordManager
    {
        private static MaintenanceRecordManager manager;
        public static MaintenanceRecordManager Instance
        {
            get
            {
                if (manager == null)
                    manager = new MaintenanceRecordManager();
                return manager;
            }
        }

        /// <summary>
        /// 根据主键编号获取对象
        /// </summary>
        /// <param name="AutoID"></param>
        /// <returns></returns>
        public APIResponseData MaintenanceRecordSingleByAutoID(int AutoID)
        {
            APIResponseData result = new APIResponseData { Code = -1, Message = "未能获取到数据！" };
            try
            {
                switch (Models.Config.Configurations.Properties.ConnType?.ToLower())
                {
                    case "api":
                        result = ApiHelper.Instance.SendMessage(new HttpItem
                        {
                            URL = ServiceRoute.MaintenanceRecordSingleByAutoID,
                            Method = "Post",
                            ContentType = "application/json;charset=utf-8",
                            Postdata = JsonConvert.SerializeObject(new { autoid = AutoID })
                        });
                        break;

                    default:
                        result = Data.MaintenanceRecordManager.MaintenanceRecordAccess.Instance.SingleByAutoID(AutoID);
                        break;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
            }
            return result;
        }

    }
}
