package com.tzy.base.dto;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import com.tzy.common.annotation.Desensit;
import com.tzy.common.enums.DesensitType;
import com.tzy.common.utils.BeanUtil;
import com.tzy.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BankInfoDto {

    private Integer id;

    private Integer userId;
    //银行卡类型
    private String bankType;
    //银行卡名称
    private String bankName;
    //银行卡名称
    @Desensit
    private String bankNo;
    //协议号
    @Desensit(type = DesensitType.NULL)
    private String msgId;
    //绑定时间
    private Date createTime;
    //解绑时间
    private Date unbandingTime;
    //状态：0 预绑定 1 绑定成功，2 解绑
    private Integer status;
    //配置参数
    @Desensit(type = DesensitType.NULL)
    private String configData;
    //平台
    private String type;

    @Desensit(type = DesensitType.NULL)
    private String account;

    private String typeCode;

    private Integer merchantId;

    private String accountType;

    private BigDecimal balance;
    //是否免费支付 0=否 1=是
    private Integer freePay;

    @Desensit(type = DesensitType.NULL)
    private JSONObject configDataJson;

    public JSONObject getConfigDataJson(){
        return
                StringUtils.isNotEmpty(this.configData) ?
                JSONObject.parseObject(this.configData)
                : null
                ;
    }
    public BankInfoDto(Integer merchantId,String accountType ,String type){
        this.merchantId =merchantId;
        this.accountType =accountType;
        this.type = type;
    }

    public BankInfoDto(Integer userId,String account,String type,String typeCode){
        this.userId =userId;
        this.account =account;
        this.type = type;
        this.typeCode = typeCode;
    }

    public BankInfoDto(Integer userId,String bankType,String bankName,String bankNo,String msgId,String type ){
        this.userId = userId;
        this.bankType = bankType;
        this.bankName = bankName;
        this.bankNo = bankNo;
        this.msgId = msgId;
        this.type = type;
    }


    public String desensitization(){
        this.userId = null;
        this.msgId = null;
        String bankNo = "";
        JSONObject configDataJson = getConfigDataJson();
        if(null != configDataJson && !configDataJson.isEmpty()){
            bankNo = configDataJson.getString("bankNo");
        }
        this.configData = null;
        return StringUtil.isEmpty("bankNo") ? "":bankNo.substring(bankNo.length()-6,bankNo.length());
    }




}
