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

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

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

        /// <summary>
        /// 获取全部数据
        /// </summary>
        /// <returns></returns>
        public List<sysConfig> GetAll()
        {
            List<sysConfig> lst = null;

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

                        APIResponseData result = ApiHelper.Instance.SendMessage(new HttpItem
                        {
                            URL = ServiceRoute.GetAllSystemConfig,
                            Method = "Post",
                            ContentType = "application/json; charset=utf-8"
                        });

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

                        #endregion
                        break;
                    case "sql":
                        #region sql

                        lst = SystemConfigAccess.Instance.GetAll();

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

            return lst;
        }

    }
}
