using Newtonsoft.Json;
using ProjectManagementSystem.WebApiClient.Service;
using ProjectManagementSystem.Common.Log;
using ProjectManagementSystem.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.Common.WebApi
{
    public class ScaleApi
    {
        private static RestApi<ScaleResponse> restApi = new RestApi<ScaleResponse>();

        /// <summary>
        /// POST请求
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="apiName">接口名</param>
        /// <param name="pars">Params参数，可null</param>
        /// <param name="body">Body对象，可null</param>
        /// <param name="data">返回数据对象</param>
        /// <returns>调用成功返回True</returns>
        public static bool Post<T>(string url, object pars, object body, out T data, out string msg)
        {
            data = default(T);
            msg = default(string);
            try
            {
                var res = restApi.Post(url, pars, body, out string content);
                CLog.Instance.GetLog("System").WriteDebug($"POST回复：{url}，{content}");

                if (res.DATA != null)
                {
                    //var response = JsonConvert.DeserializeObject<ScaleResponse>(content);
                    data = JsonConvert.DeserializeObject<T>(res.DATA.ToString());
                }

                msg = res.MSG;
                return res.CODE == "0000";
            }
            catch (Exception ex)
            {
                CLog.Instance.GetLog("System").WriteException("Exception", ex);
            }

            return false;
        }
    }
}

