using CsharpHttpHelper;
using DeviceRepairAndOptimization.Data;
using DeviceRepairAndOptimization.Models;
using DeviceRepairAndOptimization.Utils;
using Newtonsoft.Json;
using System;

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

        /// <summary>
        /// 调用接口数据/sql数据
        /// </summary>
        /// <param name="serverUrl"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public APIResponseData LoginCodeExist(string loginCode)
        {
            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.LoginCodeExist,
                            Method = "Post",
                            ContentType = "application/json;charset=utf-8",
                            Postdata = JsonConvert.SerializeObject(new { loginCode })
                        });
                        break;
                    default:
                        result = UserAccess.Instance.LoginCodeExist(loginCode);
                        break;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
            }
            return result;
        }
    }
}
