using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using MySystem.Models.Main;
using Library;
using LitJson;
using System.Threading;

namespace MySystem
{
    /// <summary>
    /// 好哒测试服务
    /// </summary>
    public class TestHaoDaService
    {
        public readonly static TestHaoDaService Instance = new TestHaoDaService();
        private TestHaoDaService()
        { }

        public void Start()
        {
            Thread th = new Thread(StartListen);
            th.IsBackground = true;
            th.Start();
        }

        public void StartListen()
        {
            // QueryAuthStatus(813);//查询实名认证状态
            // ChangeMerchantCard(1);//商户修改银行卡
        }

        //添加分账接收方账户
        public void AddOpenDivideAccounts(int MerchantId)
        {
            WebCMSEntities db = new WebCMSEntities();
            MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
            string result = HaoDaHelper.Instance.AddOpenDivideAccounts(AddOpenDivideAccountsUtil.AddValue(AddInfo));
            db.Dispose();
        }

        //商户开通分账
        public void OpenDivideAccounts(int MerchantId)
        {
            WebCMSEntities db = new WebCMSEntities();
            MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
            string result = HaoDaHelper.Instance.OpenDivideAccounts(AddInfo.OutMchtNo, AddInfo.StoreNo);
            db.Dispose();
        }

        //分账接收方签约
        public void DivideAccountsSign(int MerchantId)
        {
            WebCMSEntities db = new WebCMSEntities();
            MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
            string result = HaoDaHelper.Instance.DivideAccountsSign("230817000000000278", AddInfo.OutMchtNo, AddInfo.StoreNo);
            db.Dispose();
        }

        //查询实名认证状态
        public void QueryAuthStatus(int MerchantId)
        {
            WebCMSEntities db = new WebCMSEntities();
            MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
            string result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo);
            db.Dispose();
        }

        //商户修改银行卡
        public void ChangeMerchantCard(int MerchantId)
        {
            WebCMSEntities db = new WebCMSEntities();
            // MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
            // var request = TestChangeMerchantCardSetUtil.SetValue(AddInfo);
            // JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.ChangeMerchantCard(request));
            // JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, Infos["taskId"].ToString()));
            //TODO:修改结算卡变更商户相关信息
            // AccountNumber
            // BankName
            // BankBranchId
            // BankAddressCode
            // BankAccountType
            // OpenUnionNo
            // OpenCollectBankCode
            // OpenBankRegionCode
            // OpenBankAccout
            // OpenBankAccName
            // ZbankRegionCode
            // ZBankNo
            db.Dispose();
        }
    }
}