package com.tzy.framework.pay.dto;

import com.alibaba.fastjson.JSONObject;
import com.tzy.common.dto.Result;
import com.tzy.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BankInfo<T> extends Result {

    public BankInfo(Integer userId,String bankType, String bankNo, String realName, String cardNo, String phone){
        this.userId = userId;
        this.bankType = bankType;
        this.bankNo = bankNo;
        this.realName = realName;
        this.cardNo = cardNo;
        this.phone = phone;
    }
    //用户id
    private Integer userId;
    //银行卡号
    private String bankNo;
    //银行卡名
    private String bankName;
    //银行卡类型 卡类型 101 借记卡，102 信用卡
    private String bankType;
    //姓名
    private String realName;
    //身份证号
    private String cardNo;
    //手机号
    private String phone;
    //预签约唯一码
    private String uniqueCode;
    //短信验证码
    private String phoneCode;
    //协议号： 1202304241415275791952576173
    private String protocolNo = "1202304241415275791952576173";
    //协议列表
    private String protocols;

    public BankInfo setConfirm(String uniqueCode,String phoneCode){
        this.uniqueCode = uniqueCode;
        this.phoneCode = phoneCode;
        return this;
    }
    public BankInfo setProtocolNo(String protocolNo){
        this.protocolNo = protocolNo;
        return this;
    }

    //账户信息[银行卡号|持卡人姓名|证件号|手机号|银行卡安全码|银行卡有效期]
    public String getFormat(){
       StringBuffer stb = new StringBuffer();
       return stb.append(StringUtils.isNotEmpty(bankNo) ? bankNo+"" : "")
                       .append("|")
           .append(StringUtils.isNotEmpty(realName) ? realName : "")
               .append("|")
           .append(StringUtils.isNotEmpty(cardNo) ? cardNo : "")
               .append("|")
           .append(StringUtils.isNotEmpty(phone) ? phone : "")
               .append("||").toString();
    }

    private JSONObject payConfig;

    public T getPayConfigByClass( Class<T> clazz){
        return JSONObject.parseObject(payConfig.toJSONString(), clazz);
    }

    public static BankInfo ok(){
        return new BankInfo();
    }

    public static BankInfo ok(String msg) {
        return new BankInfo(true,200,msg);
    }

    public BankInfo success() {
        this.setSuccess(true);
        this.setCode(0);
        return this ;
    }
    public BankInfo success(String msg) {
        this.setSuccess(true);
        this.setCode(0);
        this.setMsg(msg);
        return this ;
    }

    public BankInfo fail(String msg) {
        this.setSuccess(false);
        this.setCode(-1);
        this.setMsg(msg);
        return this ;
    }
    public static BankInfo error(String msg) {
        return new BankInfo(false, -1, msg);
    }
    public BankInfo(boolean success, Integer code, String msg){
        this.setSuccess(success);
        this.setCode(code);
        this.setMsg(msg);
    }

}
