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

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

        /// <summary>
        /// 获取表结构数据
        /// </summary>
        /// <param name="tblName"></param>
        /// <returns></returns>
        public APIResponseData GetColumnInfo(string tblName)
        {
            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.GetColumnInfo,
                            Method = "Post",
                            ContentType = "application/json;charset=utf-8",
                            Postdata = JsonConvert.SerializeObject(new { tblname = tblName })
                        });
                        break;

                    default:
                        result = CommonAccess.Instance.GetColumnInfo(tblName);
                        break;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
            }
            return result;
        }


    }
}
