using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aop.Api.Util;
using GraphQL;
using Library;
using LitJson;
using MySystem;
using MySystem.Models.Main;

namespace MySystem
{
    /// <summary>
    /// 好哒商户修改银行卡参数赋值(测试)
    /// </summary>
    public class TestChangeMerchantCardSetUtil
    {
        // bankCard	银行卡正面	结算类型为1和2时必填，0不填，传上传图片接口得到的token
        // openAccountLicenses	开户许可证	企业类型商户或结算类型为0时必填，1和2不填，传上传图片接口得到的token
        // priLicAgreement	企业法人对私授权书	结算类型为1且为企业商户时必填，传上传图片接口得到的token
        // agentProtocol	委托结算授权书	结算类型为2时必填，传上传图片接口得到的token
        // agentIdCardFront	被委托人身份证人像面	结算类型为2时必填，传上传图片接口得到的token
        // agentIdCardBack	被委托人身份证国徽面	结算类型为2时必填，传上传图片接口得到的token
        // holdAgentProtocol	法人手持委托结算授权书	结算类型为2时必填，传上传图片接口得到的token
        public static ChangeMerchantCard SetValue(MerchantAddInfo AddInfo, string BankCard = "/static/upload/2024/3/12/Card.jpg")
        {
            ChangeMerchantCard changeMerchantCard = new ChangeMerchantCard();
            changeMerchantCard.mchtNo = "030510106722615"; //收款商户号
            changeMerchantCard.accountNo = "694330345"; //卡号(账户类型 0-对公 时填写对公账号，1-对私 时填写银行卡号)
            changeMerchantCard.accoutType = "0"; //账户类型 0-对公，1-对私
            if (changeMerchantCard.accoutType == "1")
            {
                changeMerchantCard.accountName = "黄全芳"; //开户名（账户名称 账户类型 0-对公 时填写对公账户名，1-对私 时填写银行卡户名）
            }
            else
            {
                changeMerchantCard.accountName = "四川佰人商贸有限公司"; //开户名（账户名称 账户类型 0-对公 时填写对公账户名，1-对私 时填写银行卡户名）
            }
            changeMerchantCard.zbankNo = "305651000261"; //开户支行号
            changeMerchantCard.alterType = "0"; //结算类型：0-对公结算银行卡；1-法人对私结算银行卡；2-非法人结算
            // if (AddInfo.AccountType == "0" && AddInfo.LicenceType == "0") changeMerchantCard.alterType = "0"; //结算类型：0-对公结算银行卡；1-法人对私结算银行卡；2-非法人结算
            // if (AddInfo.AccountType == "1" && (AddInfo.LicenceType == "0" || AddInfo.LicenceType == "1")) changeMerchantCard.alterType = "1"; //结算类型：0-对公结算银行卡；1-法人对私结算银行卡；2-非法人结算
            // if (AddInfo.AccountType == "1" && AddInfo.LicenceType == null) changeMerchantCard.alterType = "2"; //结算类型：0-对公结算银行卡；1-法人对私结算银行卡；2-非法人结算
            changeMerchantCard.acctZbankCode = "510107"; //开户支行地区码
            // changeMerchantCard.idCard = ""; //非法人身份证号
            // if (changeMerchantCard.alterType == "2")
            // {
            //     changeMerchantCard.idCard = "340123200410150349"; //非法人身份证号(结算类型为2时必填)
            //     if (AddInfo.CardPeriodEnd.Value.Year == 2050)
            //     {
            //         changeMerchantCard.agentCardDate = AddInfo.CardPeriodBegin.Value.ToString("yyyyMMdd") + "-" + "长期"; //法人身份证有效期 格式：20150101-20200101，若结束日期为长期填20150101-长期
            //     }
            //     else
            //     {
            //         changeMerchantCard.agentCardDate = AddInfo.CardPeriodBegin.Value.ToString("yyyyMMdd") + "-" + AddInfo.CardPeriodEnd.Value.ToString("yyyyMMdd"); //法人身份证有效期 格式：20150101-20200101，若结束日期为长期填20150101-长期
            //     }
            //     // changeMerchantCard.agentCardDate = "" + "-" + "长期"; //非法人身份证有效期(结算类型为2时必填，格式：20210101-20220101，如长期：20210101-长期)
            //     // changeMerchantCard.agentCardDate = "" + "-" + ""; //非法人身份证有效期(结算类型为2时必填，格式：20210101-20220101，如长期：20210101-长期)
            // }
            List<PhotoItem> photoList = new List<PhotoItem>();
            PhotoItem photoItem = new PhotoItem();
            // alterType结算类型为 0 时，上传 开户许可证照片
            // alterType结算类型为1时，上传 银行卡照片
            // alterType结算类型为2时，上传 银行卡照片、非法人身份证正面照片、非法人身份证反
            // 面照片、委托结算授权书照片、法人手持委托结算授权书
            if (changeMerchantCard.alterType == "0")
            {
                var tokenInfo = JsonMapper.ToObject(HaoDaHelper.Instance.GetToken(AddInfo.BankCard.Substring(AddInfo.BankCard.LastIndexOf("/")).Trim('/'), "0", AddInfo.BrandId));
                if (tokenInfo["code"].ToString() == "1")
                {
                    var returnInfo = HaoDaHelper.Instance.ReturnFileName(tokenInfo["token"].ToString(), AddInfo.BankCard, AddInfo.BrandId);
                    if (returnInfo != "false")
                    {
                        photoItem = new PhotoItem();
                        photoItem.mediaCode = "openAccountLicenses";
                        photoItem.mediaPath = returnInfo;
                        photoList.Add(photoItem);
                    }
                }
            }
            if (changeMerchantCard.alterType == "1")
            {
                var info = "/static/upload/2024/3/12/Card.jpg";
                if (!string.IsNullOrEmpty(info))
                {
                    var tokenInfo = JsonMapper.ToObject(HaoDaHelper.Instance.GetToken(info.Substring(info.LastIndexOf("/")).Trim('/'), "0", AddInfo.BrandId));
                    if (tokenInfo["code"].ToString() == "1")
                    {
                        var returnInfo = HaoDaHelper.Instance.ReturnFileName(tokenInfo["token"].ToString(), info, AddInfo.BrandId);
                        if (returnInfo != "false")
                        {
                            photoItem = new PhotoItem();
                            photoItem.mediaCode = "openAccountLicenses";
                            photoItem.mediaPath = returnInfo;
                            photoList.Add(photoItem);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(BankCard))
                {
                    var tokenInfo = JsonMapper.ToObject(HaoDaHelper.Instance.GetToken(BankCard.Substring(BankCard.LastIndexOf("/")).Trim('/'), "0", AddInfo.BrandId));
                    if (tokenInfo["code"].ToString() == "1")
                    {
                        var returnInfo = HaoDaHelper.Instance.ReturnFileName(tokenInfo["token"].ToString(), BankCard, AddInfo.BrandId);
                        if (returnInfo != "false")
                        {
                            photoItem = new PhotoItem();
                            photoItem.mediaCode = "bankCard";
                            photoItem.mediaPath = returnInfo;
                            photoList.Add(photoItem);
                        }
                    }
                }
            }
            if (changeMerchantCard.alterType == "2")
            {
                var tokenInfo = JsonMapper.ToObject(HaoDaHelper.Instance.GetToken(AddInfo.BankCard.Substring(AddInfo.BankCard.LastIndexOf("/")).Trim('/'), "0", AddInfo.BrandId));
                if (tokenInfo["code"].ToString() == "1")
                {
                    var returnInfo = HaoDaHelper.Instance.ReturnFileName(tokenInfo["token"].ToString(), AddInfo.BankCard, AddInfo.BrandId);
                    if (returnInfo != "false")
                    {
                        photoItem = new PhotoItem();
                        photoItem.mediaCode = "openAccountLicenses";
                        photoItem.mediaPath = returnInfo;
                        photoList.Add(photoItem);
                    }
                }
            }
            changeMerchantCard.photoList = photoList; //图片列表
            return changeMerchantCard;
        }
    }
}