using BasePaySdk.Request;
using BasePaySdk;
using JiaZhiQuan.Common.Config;
using Newtonsoft.Json;
using System.Collections.Generic;
using System;
using Wicture.DbRESTFul;

namespace JiaZhiQuan.Common.JuheAPI.HuiFu {
    public class HuiFuApiChash {
        /// <summary>
        /// 汇付天下-提现
        /// </summary>
        /// <param name="huifuConf"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public static BaseRequest InitReq(HuiFuCommonConfig huifuConf,
            HuiFuChashInfo info) {
            // 2.组装请求参数
            V2TradeSettlementEnchashmentRequest request = new V2TradeSettlementEnchashmentRequest();
            // 请求日期
            request.setReqDate(DateTime.Now.ToString("yyyyMMdd"));
            // 请求流水号
            request.setReqSeqId(info.reqId);
            // 取现金额
            request.setCashAmt(CommonUtils.DivideAndRound(info.cash_amt, 100).ToString("0.00"));
            if (huifuConf.isDev) {
                request.setCashAmt("0.01");//测试
            }
            
            // 取现方ID号
            request.setHuifuId(info.huifu_id);
            // 到账日期类型
            request.setIntoAcctDateType("T1");
            // 取现卡序列号
            request.setTokenNo(info.token_no);

            // 设置非必填字段
            Dictionary<string, object> extendInfoMap = getExtendInfos(huifuConf, info);
            request.setExtendInfo(extendInfoMap);
            return request;
        }

        /**
        * 取现-非必填字段
        * @return
        */
        private static Dictionary<string, object> getExtendInfos(HuiFuCommonConfig huifuConf,
            HuiFuChashInfo info) {
            // 设置非必填字段
            Dictionary<string, object> extendInfoMap = new Dictionary<string, object>();
            // 账户号
            // extendInfoMap.Add("acct_id", "");
            // 取现渠道
            extendInfoMap.Add("enchashment_channel", "00");
            // 备注
            extendInfoMap.Add("remark", JsonConvert.SerializeObject(info.Remark));
            // 异步通知地址
            extendInfoMap.Add("notify_url", info.notifyUrl);
            return extendInfoMap;
        }
    }
}
