using HKLib.Dto;
using HKLib.RabbitMQ.Config;
using HKLib.RabbitMQ.Publisher;
using Newtonsoft.Json.Linq;
using XExten.Advance.HttpFramework.MultiCommon;
using XExten.Advance.HttpFramework.MultiFactory;
using XExten.Advance.LinqFramework;

namespace HKLib.Interfaces
{
    public class HKLibHelper
    {
        /// <summary>
        /// 设置刷卡时间端
        /// </summary>
        public static bool SetTime(TimeSpilte input)
        {
            IHttpMultiClient.HttpMulti.AddNode(t =>
            {
                t.NodePath = $"{Configer.SaasRoute}";
                t.JsonParam = input.ToJson();
                t.ReqType = MultiType.POST;
            }).Build().RunStringFirst();
            return true;
        }

        /// <summary>
        /// 添加机构
        /// </summary>
        public static string SetOrg(string input)
        {
            return IHttpMultiClient.HttpMulti.AddNode(t =>
              {
                  t.NodePath = $"{Configer.SaasRoute}/api/one-card/member-tag";
                  t.ReqType = MultiType.POST;
                  t.JsonParam = (new { Name = input }).ToJson();
              }).Build().RunStringFirst().ToModel<JObject>()["data"]["id"].ToString();
        }

        /// <summary>
        /// 修改机构
        /// </summary>
        public static bool AlterOrg(string input, string Sid)
        {
            return IHttpMultiClient.HttpMulti.AddNode(t =>
            {
                t.NodePath = $"{Configer.SaasRoute}/api/one-card/member-tag";
                t.ReqType = MultiType.PUT;
                t.JsonParam = (new { Name = input, Id = Sid }).ToJson();
            }).Build().RunStringFirst().ToModel<JObject>()["isSuccess"].ToString().AsBool();
        }

        /// <summary>
        /// 根据用户命获取下拉用户列表
        /// </summary>
        /// <param name="keyword"></param>
        public static string GetUserList(string keyword)
        {
            IHttpMultiClient.HttpMulti.AddNode(t =>
            {
                t.NodePath = $"{Configer.SaasRoute}/{keyword}";
                t.ReqType = MultiType.GET;
            }).Build().RunStringFirst();
            return "";
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="input"></param>
        public static void AddUser(UserDto input)
        {
            IHttpMultiClient.HttpMulti.AddNode(t =>
            {
                t.NodePath = $"{Configer.SaasRoute}";
                t.ReqType = MultiType.POST;
                t.JsonParam = input.ToJson();
            }).Build().RunStringFirst();
        }
        /// <summary>
        /// 变更卡状态 销户
        /// </summary>
        /// <param name="input"></param>
        public static void CardStutasChange(CardStutasDto input)
        {
            input.CardNo = GetUserList(input.keywrod);

            IHttpMultiClient.HttpMulti.AddNode(t =>
            {
                t.NodePath = $"{Configer.SaasRoute}";
                t.ReqType = MultiType.POST;
                t.JsonParam = input.ToJson();
            }).Build().RunStringFirst();
            ServiceQueryPush.QueryPush.PushMQ(input, "CardStutasChanged", MQEnum.Top);
        }
        /// <summary>
        /// 报表数据
        /// </summary>
        /// <param name="input"></param>
        /// <param name="type">1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表</param>
        public static void Report(ReportDto input, int type = 1)
        {
            IHttpMultiClient.HttpMulti.AddNode(t =>
            {
                t.NodePath = $"{Configer.SaasRoute}";
                t.ReqType = MultiType.POST;
                t.JsonParam = input.ToJson();
            }).Build().RunStringFirst();
        }
    }
}
