/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.dm.user.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import javax.persistence.Entity;
import javax.persistence.Table;

import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.domain.Role;
import org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.Set;

/**
* @website https://el-admin.vip
* @description /
* @author shiguangji
* @date 2021-03-09
**/
@Entity
@Data
@Table(name="dm_user")
public class DmUser extends BaseEntity implements Serializable {

    @Id
    @Column(name = "id")
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "id")
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private String id;

    @Column(name = "name",nullable = false)
//    @NotBlank
    @ApiModelProperty(value = "姓名")
    private String name;

    @Column(name = "sex")
    @ApiModelProperty(value = "性别")
    private String sex;

    @Column(name = "contacts")
    @ApiModelProperty(value = "联系方式")
    private String contacts;

    @Column(name = "email",nullable = false)
//    @NotBlank
    @ApiModelProperty(value = "邮箱")
    private String email;

    @ManyToMany(fetch=FetchType.EAGER)
    @ApiModelProperty(value = "用户角色")
    @JoinTable(name = "dm_users_roles",
            joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")})
    private Set<Role> roles;

    @ManyToMany(fetch=FetchType.EAGER)
    @ApiModelProperty(value = "用户岗位")
    @JoinTable(name = "dm_users_jobs",
            joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "job_id",referencedColumnName = "job_id")})
    private Set<Job> jobs;

    @OneToOne
    @JoinColumn(name = "dept_id")
    @ApiModelProperty(value = "用户部门")
    private Dept dept;

    @Column(name = "is_approver")
    @ApiModelProperty(value = "是否是审批人")
    private Boolean isApprover = false;

    @Column(name = "usertype",nullable = false)
    @ApiModelProperty(value = "人员种类(00-正式人员、01-外协单位、02-租户、03-访客)")
    private String usertype;

    @Column(name = "enabled")
    @ApiModelProperty(value = "在职状态")
    private String enabled;

    @Column(name = "picture")
    @ApiModelProperty(value = "人脸照片")
    private String picture;

    @Column(name = "user_number",nullable = false)
    @ApiModelProperty(value = "员工工号")
    private String userNumber;

    @Column(name = "remark")
    @ApiModelProperty(value = "备注")
    private String remark;

    @Column(name = "status")
    @ApiModelProperty(value = "登记状态")
    private String status;

    @Column(name = "company",nullable = false)
    @ApiModelProperty(value = "单位")
    private String company;

    @Column(name = "card_id",nullable = false)
    @ApiModelProperty(value = "卡号")
    private String cardId;


    public void copy(DmUser source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}