package com.jeequan.jeepay.db.entity;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.Objects;

/**
 * <p>
 * 商户信息表
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2021-04-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "t_mch_info", autoResultMap = true)
public class MchInfo extends com.jeequan.jeepay.core.entity.MchInfo {

    //gw
    public static final LambdaQueryWrapper<MchInfo> gw(){
        return new LambdaQueryWrapper<>();
    }

    private static final long serialVersionUID=1L;

    public static final byte TYPE_NORMAL = 1; //商户类型： 1-普通商户
    public static final byte TYPE_ISVSUB = 2; //商户类型： 2-特约商户

    public static final String REFUND_MODEL_PLAT = "plat"; // 支持的退款方式 平台
    public static final String REFUND_MODEL_API = "api"; // 支持的退款方式 接口

    public static final String MCH_LEVEL_M0 = "M0"; // 商户级别：简单
    public static final String MCH_LEVEL_M1 = "M1"; // 商户级别：高级

    public static final byte STATE_NO = 0; // 商户状态: 0-停用
    public static final byte STATE_YES = 1; // 商户状态: 1-正常
    public static final byte STATE_NO_MGR = 2; // 商户状态: 2-由运营平台停用

    /**
     * 商户号
     */
    @TableId(value = "mch_no", type = IdType.INPUT)
    private String mchNo;

    /**
     * 支持的退款方式 ["plat", "api"]
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private JSONArray refundMode;

    @TableField(exist = false)
    private String mchServiceName;

    @TableField(exist = false)
    private String mchServicePhone;

    @TableField(exist = false)
    private Date firstDate;

    @TableField(exist = false)
    private Date lastDate;

    public static boolean isIsv(MchInfo mchInfo) {
        if (mchInfo == null) {
            return false;
        }

        return Objects.equals(TYPE_ISVSUB, mchInfo.getType());
    }

    public static boolean isNotIsv(MchInfo mchInfo) {
        if (mchInfo == null) {
            return true;
        }

        return !Objects.equals(TYPE_ISVSUB, mchInfo.getType());
    }
}
