using CsharpHttpHelper;
using DeviceRepair.DataAccess;
using DeviceRepair.Models;
using DeviceRepair.Models.Logs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

        /// <summary>
        /// 用户登录登出日志
        /// </summary>
        /// <param name="FilterInfo"></param>
        /// <returns></returns>
        public APIResponseData UserLoginContent(OperationFilterModel FilterInfo)
        {
            APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据！" };
            try
            {
                switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
                {
                    case "api":
                        apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
                        {
                            URL = ServiceRouteConstValue.UserLoginContent,
                            Method = "Post",
                            ContentType = "application/json; charset=utf-8",
                            Postdata = JsonConvert.SerializeObject(FilterInfo)
                        });
                        break;
                    case "sql":
                        apiResponseData = OperationAccess.Instance.UserLoginContent(FilterInfo);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                apiResponseData.Code = -1;
                apiResponseData.Message = ex.Message;
            }
            return apiResponseData;
        }
    }
}
