/*
*  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.dmuser.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
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 me.zhengjie.ykt.domain.DmRoomDevice;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.Set;

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

    @Id
    @NotNull(groups = BaseEntity.Update.class)
    @Column(name = "id")
    @ApiModelProperty(value = "主键")
    private String id;

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

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

    @Column(name = "email")
    @ApiModelProperty(value = "邮箱地址")
    private String email;

    @Column(name = "contacts")
    @ApiModelProperty(value = "手机")
    private String contacts;

    @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;

    @ManyToMany(fetch=FetchType.EAGER)
    @ApiModelProperty(value = "门禁设备")
    @JoinTable(name = "dm_users_devices",
            joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "room_device_id",referencedColumnName = "id")})
    private Set<DmRoomDevice> dmRoomDevices;

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

    @Column(name = "is_approver")
    @ApiModelProperty(value = "是否是审批人(1-是,0-否)")
    private Long isApprover;

    @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));
    }
}