package com.keyware.shandan.bianmu.entity;


import com.baomidou.mybatisplus.annotation.*;
import com.keyware.shandan.common.entity.BaseEntity;
import com.keyware.shandan.system.entity.SysOrg;
import com.keyware.shandan.system.entity.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * 目录成员表
 *
 * @author Administrator
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("B_DIRECTORY_MEMBERS")
public class DirectoryMembersVo extends BaseEntity {
    private static final long serialVersionUID = 3607497508629796938L;
    /**
     * 主键，自增
     */
    @TableId(value = "ID", type = IdType.AUTO)
    private Integer id;
    /**
     * 目录ID
     */
    @TableField("DIRECTORY_ID")
    private String directoryId;
    /**
     * 成员ID
     */
    @TableField("MEMBER_ID")
    private String memberId;
    /**
     * 成员名称
     */
    @TableField("MEMBER_NAME")
    private String memberName;
    /**
     * 成员类型
     */
    @TableField("MEMBER_TYPE")
    private MemberType memberType;
    /**
     * 成员权限类型
     */
    @TableField("PERMIS_TYPE")
    private String permisType;
    /**
     * 是否应用到子节点
     */
    @TableField("APPLY_CHILDREN")
    private Boolean applyChildren;

    /**
     * 设置部门
     *
     * @param org
     */
    public void setOrg(SysOrg org) {
        this.memberType = MemberType.ORG;
        this.memberId = org.getId();
        this.memberName = org.getOrgName();
    }

    /**
     * 设置用户
     *
     * @param user
     */
    public void setUser(SysUser user) {
        this.memberType = MemberType.USER;
        this.memberId = user.getUserId();
        this.memberName = user.getUserName();
    }

    /**
     * @return 获取成员类型描述
     */
    public String getMemberTypeDesc() {
        return memberType.getDesc();
    }

    public boolean isUser() {
        return memberType == MemberType.USER;
    }
    public boolean isOrg() {
        return memberType == MemberType.ORG;
    }

    /**
     * 成员类型
     */
    @Getter
    @AllArgsConstructor
    public enum MemberType {
        /**
         * 组织
         */
        ORG("ORG", "部门"),
        /**
         * 人员
         */
        USER("USER", "用户");

        @EnumValue
        private final String value;
        private final String desc;
    }
}
