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

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.Excels;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.ValidGroup;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 et_user
 *
 * @author qiuzhenzhao
 */
@Data
public class User extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 用户ID */
    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    @ApiModelProperty(value = "用户ID")
    @NotNull(message = "用户ID不能为空", groups = {ValidGroup.Update.class})
    private Long userId;

    /** 部门ID */
    @Excel(name = "部门编号", type = Type.IMPORT)
    private Long deptId;

    /** 用户账号 */
    @Excel(name = "登录名称")
    private String userName;

    /** 真实姓名 */
    @Excel(name = "真实姓名")
    @NotBlank(message = "真实姓名不能为空", groups = {ValidGroup.CreateCleaner.class, ValidGroup.CreatePartner.class})
    private String realName;

    /** 身份证号 */
    @Excel(name = "身份证号")
    private String idCard;

    /** 用户昵称 */
    @Excel(name = "用户名称")
    private String nickName;

    /** 用户邮箱 */
    @Excel(name = "用户邮箱")
    private String email;

    /** 手机号码 */
    @Excel(name = "手机号码")
    @NotBlank(message = "手机号码不能为空", groups = {ValidGroup.CreateCleaner.class, ValidGroup.CreatePartner.class})
    private String phonenumber;

    /** 出生年月 */
    @Excel(name = "出生年月")
    private String birthday;

    /** 用户性别 */
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    /** 用户头像 */
    private String avatar;

    /** 密码 */
    private String password;

    /** 支付密码 */
    private String payPassword;

    /** 用户类型 */
    private String userType;

    /** 部门对象 */
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    private SysDept dept;


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

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

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

    /** 最后登录时间 */
    @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;

    /** 是否认证：0-未认证；1-已认证 */
    public Boolean isAuthentication;

    /** 展示当前设备id */
    private Long deviceId;

    /** 微信openid */
    private String wxopenid;

//    /** 支付渠道 */
//    public Long payChannel;

    @Excel(name = "自定义渠道ID列表")
    @ApiModelProperty("自定义渠道ID列表")
    private List<Long> channelIds;

    /** 分账比例 */
    @NotNull(message = "分账比例不能为空", groups = {ValidGroup.CreatePartner.class})
    private BigDecimal dividendProportion;

    /** 商户id */
    private Long merchantId;

    /** 角色对象 */
    private List<SysRole> roles;

    /** 角色组 */
    private Long[] roleIds;

    /** 角色ID */
    private Long roleId;

    /** 店铺ID */
    @NotNull(message = "店铺ID不能为空", groups = {ValidGroup.CreateCleaner.class, ValidGroup.CreatePartner.class})
    private Long storeId;

    /** 服务费比例 */
    @Excel(name = "服务费比例")
    private BigDecimal serviceFeeProportion;

    @ApiModelProperty(value = "保洁时长")
    private Integer cleanDuration;

    @ApiModelProperty(value = "保洁通知:1-通知给商户；2-通知给保洁")
    private String cleanNotice;

    @ApiModelProperty(value = "取消时长设置")
    private Integer agoCancel;

    @ApiModelProperty(value = "违约金比例")
    private BigDecimal penalty;

    @ApiModelProperty(value = "提前开始使用时间")
    private Integer beforeTime;

    @ApiModelProperty(value = "是否设备管理员")
    private Boolean deviceAdmin;

    @ApiModelProperty(value = "app菜单ids")
    private List<Long> appMenus;

    @ApiModelProperty(value = "多店权限：1-单店；N-多店")
    private String multiStore;

    public User() {
    }

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

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

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


}
