package cn.pluss.platform.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

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

@Data
@Accessors(chain = true)
public class UserApp {
    @TableId
    @ApiModelProperty("id")
    private Long id;
    @ApiModelProperty(value = "登陆账号")
    private String loginName;
    @ApiModelProperty(value = "用户id")
    private Long userId;
    @ApiModelProperty(value = "用户名称")
    private String userName;
    @ApiModelProperty(value = "用户类型   promoter：推广人 ，staff：员工")
    private String userType;
    @ApiModelProperty(value = "员工类型   0 店长  1 收银员  2 店员")
    private Integer staffType;
    @ApiModelProperty(value = "头像")
    private String logo;
    @ApiModelProperty(value = "推广等级")
    private Integer level;
    @ApiModelProperty(value = "创建时间")

    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createDt;

    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "updateDt", fill = FieldFill.INSERT_UPDATE, update = "now()")
    private Date updateDt;

    @ApiModelProperty(value = "推广分润")
    private Double extendProfit;
    @ApiModelProperty(value = "是否实名认证 0未实名  1 审核中 2 审核失败 3 已审核")
    private Integer status;
    @ApiModelProperty(value = "粉丝分润")
    private Double fansProfit;
    @ApiModelProperty(value = "已提现分润")
    private Double cashProfit;
    @ApiModelProperty(value = "上级编码")
    private Long parentId;
    @ApiModelProperty(value = "超级服务商业务员id")
    private Long agentStaffId;
    @ApiModelProperty(value = "我的邀请码")
    private String inviteNum;
    @ApiModelProperty(value = "交易额")
    private Double tradeMoney;

    @TableField(exist = false)
    @ApiModelProperty(value = "身份证号")
    private String certnum;

    @ApiModelProperty(value = "实名认证审核失败原因")
    private String certReason;

    @TableField(exist = false)
    @ApiModelProperty(value = "开户支行")
    private String bankBranch;

    @TableField(exist = false)
    @ApiModelProperty(value = "银行名称")
    private String bankName;

    @TableField(exist = false)
    @ApiModelProperty(value = "银行卡号")
    private String bankNo;

    @TableField(exist = false)
    @ApiModelProperty(value = "银行卡绑定手机号")
    private String phone;

    @ApiModelProperty(value = "是否添加银行卡 0未添加 1 审核中 2 审核失败 3 已审核")
    private Integer bankStatus;

    @ApiModelProperty(value = "银行卡认证审核失败原因")
    private String bankReason;

    @ApiModelProperty(value = "商家编码")
    private String merchantCode;

    /**
     * 层级
     */
    private Integer sort;

    @TableField(exist = false)
    @ApiModelProperty(value = "商户简称")
    private String merchantName;

    @TableField(exist = false)
    @ApiModelProperty(value = "门店名称")
    private String storeName;

    @TableField(exist = false)
    @ApiModelProperty(value = "门店id")
    private String storeId;

    @TableField(exist = false)
    @ApiModelProperty(value = "联系人姓名")
    private String contactName;

    @TableField(exist = false)
    @ApiModelProperty(value = "经营内容描述")
    private String productDesc;

    @TableField(exist = false)
    @ApiModelProperty(value = "营业执照号")
    private String bussAuthNum;

    @TableField(exist = false)
    @ApiModelProperty(value = "通道切换字段 0 支付宝微信官方通道 1乐刷通道")
    private Integer aisleSwitch;

    @ApiModelProperty(value = "token")
    private String token;

    @ApiModelProperty(value = "是否播报  0不播报  1播报")
    private String isVoice;
    /**
     * eg. 664，868
     * 664为上级节点userId, 868为664上级节点userId
     */
    @ApiModelProperty(value = "父节点id数组")
    private String pIdArr;

    @TableField(exist = false)
    private String auditReason;

    /**
     * 1:固定费率
     * 0:不固定费率
     */
    @ApiModelProperty(value = "是否固定费率")
    private String isFixedRate;

    /**
     * 自动审核标识，标识为自动审核的服务商，推广的商户自动审核，不需要等待后台操作
     */
    @TableField("autoAudit")
    private String autoAudit;

    /**
     * 异地支付开关，为1时允许
     */
    @TableField("payEcdemicSwitch")
    private String payEcdemicSwitch;

    /**
     * 是否活动商户0：否1：是，推广的商户默认同步该状态
     */
    @TableField("isMarket")
    private String isMarket;

    /**
     * 是否开启银联支付0：不开启 1：开启，推广的商户默认同步该状态
     */
    @TableField("isUnionPay")
    private String isUnionPay;

    /**
     * 角色编码
     */
    @TableField("roleCode")
    private String roleCode;

    /**
     * 角色等级编码
     */
    @TableField("levelCode")
    private String levelCode;

    @TableField(exist = false)
    @ApiModelProperty(value = "企业类填写：营业执照名称，执照如无名称，可填“个体户XXX”（执照上姓名）；小微商户填“商户_XXX”（身份证姓名）仅传参需要 无需添加字段")
    private String licenseFullName;
    @TableField(exist = false)
    @ApiModelProperty(value = "")
    private List<MerchantImage> merchantImagesList;
    @TableField(exist = false)
    @ApiModelProperty(value = "")
    private String registUrl;

    @ApiModelProperty(value = "")
    @TableField(exist = false)
    private String password;
    @ApiModelProperty(value = "")
    @TableField(exist = false)
    private Integer merchantStatus;
    @ApiModelProperty(value = "")
    @TableField(exist = false)
    private String merchantReason;
    @TableField(exist = false)
    private String merchantType;
    @TableField(exist = false)
    private String bankCertName;

    @TableField(exist = false)
    private List<String> parentIdList;
    @TableField(exist = false)
    private String alias;
    @TableField(exist = false)
    private Double totalMoney;
    @TableField(exist = false)
    private String type;

    /**  费率，只有服务商推广的商户有这个字段 */
    @TableField(exist = false)
    private BigDecimal rate;
    //查询数据
    @TableField(exist = false)
    private Integer size;
    @TableField(exist = false)
    private Integer page;
    /** 商户id */
    @TableField(exist = false)
    private Long mercId;

    @TableField(exist = false)
    private String merchantId;

    /** 当前渠道下商户的进件状态 */
    @TableField(exist = false)
    private String merchantAuditStatus;

    /**
     * 商户信息
     */
    @TableField(exist = false)
    private MerchantBaseInfo merchantBaseInfo;
    /**
     * 结算信息
     */
    @TableField(exist = false)
    private MerchantBankCard merchantBankCard;

    /**
     * 银行卡信息
     */
    @TableField(exist = false)
    private BankCard bankCard;

    /**
     * 证件信息
     */
    @TableField(exist = false)
    private IdCard idCard;

    @TableField(exist = false)
    private Date startDate;

    @TableField(exist = false)
    private Date endDate;

    @TableField(exist = false)
    private String thirdStatus;

    @TableField(exist = false)
    private String storeId2;

    @TableField(exist = false)
    private String mcsStatus;
    @TableField(exist = false)
    private String remark;
    @TableField(exist = false)
    private String updateTime;
    @TableField(exist = false)
    private String ppStatus;
    @TableField(exist = false)
    private String ppThirdStatus;
    @TableField(exist = false)
    private String pluginRemark;
    @TableField(exist = false)
    private List<MerchantChannelStatus> channelStatusList;

    @TableField(exist = false)
    private String payPassword;

    @TableField(exist = false)
    private String permissionBill;

    @TableField(exist = false)
    private String faceCert;

    @TableField(exist = false)
    private String faceCompare;

    /**
     * 推广权限标识， 1可以推广
     */
    private String spreadFlag;

    /**
     * 用户编号
     * @date: 2022/2/16 18:32  
     */
    @TableField("userNo")
    private String userNo;

    /**
     * 用户类型标识 主要用于直营团队这边区分代理商和商户 0：表示商户1：表示代理商
     * @date: 2022/2/16 18:32
     */
    @TableField("typeMark")
    private Integer typeMark;

    /**
     * 区域合伙人标识 1：区域合伙人 0：非区域合伙人
     * @date: 2022/2/22 10:34
     */
    @TableField("areaMark")
    private Integer areaMark;

    /**
     * 登录后会生成一串密文 用于积分商城那边确认登录用户的身份
     */
    @TableField("jfShopKey")
    private String jfShopKey;

//    /**
//     * 有效状态 1：有效 -1：无效
//     */
//    @TableField("validStatus")
//    private Integer validStatus;
//
//    /**
//     * 考核到期时间
//     */
//    @TableField("validEndTime")
//    private Date validEndTime;


    /**
     * 生成一个新的用户对象
     * @return
     */
    public static UserApp newInstance() {
        UserApp userApp = new UserApp();
        Date date = new Date();
        userApp.setCreateDt(date);
        userApp.setStatus(0);
        userApp.setMerchantAuditStatus("0");
        userApp.setBankStatus(0);
        return userApp;
    }

    public static void setSort(UserApp source, UserApp target) {
        if (source == null) {
            return;
        }

        if (target == null) {
            return;
        }

        if (source.getSort() == null) {
            target.setSort(1);
        } else {
            target.setSort(source.getSort() + 1);
        }
    }


    public static void setRoleInfo(UserApp source, UserApp target,Integer typeMark) {
        if (source == null) {
            return;
        }

        if (target == null) {
            return;
        }

        if (source.getRoleCode() == null) {
            target.setRoleCode("SV2");
            target.setLevelCode("LV1");
            return;
        }

        switch (source.getRoleCode()) {
            case "ZY_BST":
                target.setRoleCode("ZY_BST");
                target.setLevelCode("T1");
                break;
            case "SV2":
                target.setRoleCode("SV2");
                target.setLevelCode("LV1");
                break;
            default:
                break;
        }
        if(typeMark != null){
            target.setTypeMark(typeMark);
        }
    }
}

