package cn.pluss.platform.vo;

import cn.pluss.platform.entity.MerchantChannelStatus;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

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

/**
 * 商户概要信息
 *
 * @author Djh
 */
@Data
public class MerchSummaryVO {

    /**
     * 用户id
     */
    private String userId;

    /**
     * 商户编号
     */
    private String merchantCode;

    /**
     * 商户简称
     */
    private String alias;

    /**
     * 创建时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 交易笔数
     */
    private Integer count;

    /**
     * 交易总金额
     */
    private BigDecimal totalFee;

    /**
     * 退款总金额
     */
    private BigDecimal retFee;

    /**
     * 退款总笔数
     */
    private Integer retCount;

    /**
     * d1进件状态
     */
    private String d1Status;

    /**
     * d1第三方进件状态值
     */
    private String d1ThirdStatus;

    /**
     * d1进件状态描述
     */
    private String d1StatusDesc;

    /**
     * d1进件备注，一般是驳回信息
     */
    private String d1Remark;

    /**
     * 微信认证状态
     */
    private String d1WxCertStatus;

    /**
     * 微信认证状态
     */
    private String d1WxCertStatusDesc;

    /**
     * d0进件状态
     */
    private String d0Status;

    /**
     * d0第三方进件状态值
     */
    private String d0ThirdStatus;

    /**
     * d0进件状态描述
     */
    private String d0StatusDesc;

    /**
     * d0进件备注，一般是驳回信息
     */
    private String d0Remark;

    /**
     * 0:商家打烊 ,1:营业中,2:系统禁用
     */
    private String d1StoreStatus;

    /**
     * 0:商家打烊 ,1:营业中,2:系统禁用
     */
    private String d0StoreStatus;

    /**
     * 微信认证状态
     */
    private String d0WxCertStatus;

    /**
     * 微信认证状态
     */
    private String d0WxCertStatusDesc;

    /**
     * 直推标记
     */
    private String directFlag;

    public static void wrapper(MerchSummaryVO merchSummaryVO) {
        String d0Remark = merchSummaryVO.getD0Remark();
        merchSummaryVO.setD0Remark(null);
        switch (merchSummaryVO.getD0Status()) {
            case "-1":
                merchSummaryVO.setD0StoreStatus("-1");
                merchSummaryVO.setD0WxCertStatus("-1");
                merchSummaryVO.setD0StatusDesc("未开通");
                break;
            case "1":
                merchSummaryVO.setD0StatusDesc("审核中");
                break;
            case "2":
                merchSummaryVO.setD0StatusDesc("已驳回");
                merchSummaryVO.setD0Remark(d0Remark);
                break;
            case "3":
            case "6":
                merchSummaryVO.setD0Status("3");
                merchSummaryVO.setD0StatusDesc("已开通");
                break;
            case "8":
                merchSummaryVO.setD0StatusDesc("待签约");
                break;
            case "0":
                if (Objects.equals(MerchantChannelStatus.AUDIT_THIRD_STATUS_WAITING, merchSummaryVO.getD0ThirdStatus())) {
                    merchSummaryVO.setD0Status("2");
                    merchSummaryVO.setD0StatusDesc("已驳回");
                    merchSummaryVO.setD0Remark(d0Remark);
                }
                break;
            default:
                merchSummaryVO.setD0Status("-1");
                merchSummaryVO.setD0StoreStatus("-1");
                merchSummaryVO.setD0WxCertStatus("-1");
                merchSummaryVO.setD0StatusDesc("未开通");
                break;
        }

        String d1Remark = merchSummaryVO.getD1StatusDesc();
        merchSummaryVO.setD1Remark(null);
        switch (merchSummaryVO.getD1Status()) {
            case "-1":
                merchSummaryVO.setD1StoreStatus("-1");
                merchSummaryVO.setD1WxCertStatus("-1");
                merchSummaryVO.setD1StatusDesc("未开通");
                break;
            case "1":
                merchSummaryVO.setD1StatusDesc("审核中");
                break;
            case "2":
                merchSummaryVO.setD1StatusDesc("已驳回");
                merchSummaryVO.setD1Remark(d1Remark);
                break;
            case "3":
            case "6":
                merchSummaryVO.setD1Status("3");
                merchSummaryVO.setD1StatusDesc("已开通");
                break;
            case "8":
                merchSummaryVO.setD1StatusDesc("待签约");
            case "0":
                if (Objects.equals(MerchantChannelStatus.AUDIT_THIRD_STATUS_WAITING, merchSummaryVO.getD1ThirdStatus())) {
                    merchSummaryVO.setD1Status("2");
                    merchSummaryVO.setD1StatusDesc("已驳回");
                    merchSummaryVO.setD1Remark(d1Remark);
                }
                break;
            default:
                merchSummaryVO.setD1Status("-1");
                merchSummaryVO.setD1StoreStatus("-1");
                merchSummaryVO.setD1WxCertStatus("-1");
                merchSummaryVO.setD1StatusDesc("未开通");
                break;
        }

        if (merchSummaryVO.getD1StoreStatus() == null) {
            merchSummaryVO.setD1StoreStatus("1");
        }

        if (merchSummaryVO.getD0StoreStatus() == null) {
            merchSummaryVO.setD0StoreStatus("1");
        }

        if ("2".equals(merchSummaryVO.getD0StoreStatus())) {
            merchSummaryVO.setD0Status("4");
            merchSummaryVO.setD0StatusDesc("已禁用");
        }

        if ("2".equals(merchSummaryVO.getD1StoreStatus())) {
            merchSummaryVO.setD1Status("4");
            merchSummaryVO.setD1StatusDesc("已禁用");
        }

        switch (merchSummaryVO.getD1WxCertStatus()) {
            case "-1":
                merchSummaryVO.setD1WxCertStatusDesc("未开通");
                break;
            case "1":
                merchSummaryVO.setD1WxCertStatusDesc("微信已授权");
                break;
            case "0":
                merchSummaryVO.setD1WxCertStatusDesc("微信未授权");
                break;
            default:
                break;
        }

        switch (merchSummaryVO.getD0WxCertStatus()) {
            case "-1":
                merchSummaryVO.setD0WxCertStatusDesc("未开通");
                break;
            case "1":
                merchSummaryVO.setD0WxCertStatusDesc("微信已授权");
                break;
            case "0":
                merchSummaryVO.setD0WxCertStatusDesc("微信未授权");
                break;
            default:
                break;
        }
    }
}
