package com.ruoyi.common.core.domain.entity;

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

import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.annotation.Excel.Type;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.interfaces.LogBizParam;
import com.ruoyi.common.enums.DesensitizedType;
import com.ruoyi.common.xss.Xss;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class User extends BaseEntity implements LogBizParam
{
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户ID")
    @Excel(name = "ID", type = Type.EXPORT, cellType = ColumnType.NUMERIC, prompt = "用户编号")
    private Long userId;

    @ApiModelProperty("代理商id")
    private Long agentId;

    @ApiModelProperty("分成比例 %")
    @Min(value = 0, message = "分成比例不能小于0%")
    @Max(value = 100, message = "分成比例不能大于100%")
    private BigDecimal point;

    @ApiModelProperty("部门ID")
    private Long deptId;

    @ApiModelProperty("登录账号")
    @Excel(name = "登录账号")
    @Xss(message = "登录账号不能包含脚本字符")
    @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
    private String userName;

    @ApiModelProperty("姓名")
    @Excel(name = "姓名")
    @Xss(message = "姓名不能包含脚本字符")
    @Size(min = 0, max = 30, message = "姓名长度不能超过30个字符")
    private String nickName;

    @ApiModelProperty("用户类型（1系统用户 2普通用户）")
    private String userType;

    @ApiModelProperty("用户邮箱")
    @Email(message = "邮箱格式不正确")
    @Size( max = 50, message = "邮箱长度不能超过50个字符")
    private String email;

    @ApiModelProperty("手机号码")
    @Size(max = 11, message = "手机号码长度不能超过11个字符")
    private String phonenumber;

    @ApiModelProperty("用户性别（0男 1女 2未知）")
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知", combo = {"男", "女", "未知"})
    private String sex;

    @ApiModelProperty("用户头像")
    private String avatar;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("帐号状态（0正常 1停用）")
    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用", combo = {"正常", "停用"})
    private String status;

    @ApiModelProperty("删除标志（0代表存在 2代表删除）")
    private String delFlag;

    @ApiModelProperty("最后登录IP")
    @Excel(name = "最后登录IP", type = Type.EXPORT)
    private String loginIp;

    @ApiModelProperty("最后登录时间")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date loginDate;

    @ApiModelProperty("角色ID")
    private Long roleId;

    @ApiModelProperty("是否实名")
    private Boolean isReal;

    @ApiModelProperty("真实姓名")
    @Sensitive(desensitizedType = DesensitizedType.USERNAME)
    private String realName;

    @ApiModelProperty("实名身份证号")
    @Sensitive(desensitizedType = DesensitizedType.ID_CARD)
    private String realIdCard;

    @ApiModelProperty("实名手机号")
    @Sensitive(desensitizedType = DesensitizedType.PHONE)
    private String realPhone;

    @ApiModelProperty("余额")
    private BigDecimal balance;

    @Excel(name = "提现服务费类型")
    @ApiModelProperty("提现服务费类型")
    private String withdrawServiceType;

    @Excel(name = "提现服务费比例/金额")
    @ApiModelProperty("提现服务费比例/金额")
    private BigDecimal withdrawServiceValue;

    @Excel(name = "所属运营区ID")
    private Long areaId;

    @Excel(name = "分成延迟到账时间")
    @ApiModelProperty("分成延迟到账时间（小时）")
    private Integer bonusDelay;

    @Excel(name = "导览列表")
    private List<String> guides;

    @Excel(name = "认证类型")
    private List<String> authTypes;

    public User(Long userId) {
        this.userId = userId;
    }

    public static User system() {
        User user = new User();
        user.setUserId(0L);
        user.setUserName("系统");
        return user;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    @Override
    public Object logBizId() {
        return userId;
    }
}
