using HH.YiDaSyncNC.Dtos;
using HH.YiDaSyncNC.Dtos.NC;
using HH.YiDaSyncNC.Dtos.YIDA;
using HH.YiDaSyncNC.Helper;
using HH.YiDaSyncNC.Models;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace HH.YiDaSyncNC.DataSync
{
    public class BX_SyncService
    {
        public string _AppType;
        public string _SystemToken;
        public string _UserId;
        public string _FormId;
        public SqlSugarClient _db;
        public SqlSugarClient _db_nc;
        public string _NCApiUrl;

        public static string _Static_PK_bd_project = ConfigurationManager.AppSettings["bd_project"];
        public static string _Static_pk_org_jt = ConfigurationManager.AppSettings["pk_org_jt"];

        public BX_SyncService(string AppType, string SystemToken, string UserId, string FormId, SqlSugarClient db, SqlSugarClient db_nc, string NCApiUrl)
        {
            _AppType = AppType;
            _SystemToken = SystemToken;
            _UserId = UserId;
            _FormId = FormId;
            _db = db;
            _db_nc = db_nc;
            _NCApiUrl = NCApiUrl;
        }
        #region 宜搭费用报销单
        public void DataSyncFYBX()
        {
            try
            {

                DingTalkService _dingTalkService = new DingTalkService(_AppType, _SystemToken, _UserId, _FormId);

                // 宜搭全量数据Id
                var serchKeyListJson = new
                {
                    //radioField_lycrvvtk = "Y",
                    //selectField_lrnh633d = "预付",

                };
                var idList = _dingTalkService.GetFormCodeList(JsonConvert.SerializeObject(serchKeyListJson));

                //LogHelper.WriteLog(JsonConvert.SerializeObject(idList.Count), "idList");
                #region 获取NC中选项数据的Id
                #endregion

                foreach (var item in idList)
                {
                    var ydDataSource = _dingTalkService.GetFormDataByCode(item);
                    string jsonData = JsonConvert.SerializeObject(ydDataSource);
                    YiDa_FYBXD thisYiDaData = JsonConvert.DeserializeObject<YiDa_FYBXD>(jsonData);//模型还未完成
                    

                }
            }
            catch (Exception ex)
            {

                throw;
            }
        }

        #endregion

        #region 宜搭差旅报销单

        public void DataSyncCLBX()
        {
            try
            {

                DingTalkService _dingTalkService = new DingTalkService(_AppType, _SystemToken, _UserId, _FormId);

                // 宜搭全量数据Id
                var serchKeyListJson = new
                {
                    //radioField_lycrvvtk = "Y",
                    //selectField_lrnh633d = "预付",

                };
                var idList = _dingTalkService.GetFormCodeList(JsonConvert.SerializeObject(serchKeyListJson));

                //LogHelper.WriteLog(JsonConvert.SerializeObject(idList.Count), "idList");
                #region 获取NC中选项数据的Id
                #endregion

                foreach (var item in idList)
                {
                    var ydDataSource = _dingTalkService.GetFormDataByCode(item);
                    string jsonData = JsonConvert.SerializeObject(ydDataSource);


                }
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        #endregion
    }
}
