package com.qmth.sop.business.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.sop.business.bean.params.SysRolePrivilegeParam;
import com.qmth.sop.common.base.BaseEntity;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.RoleTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 角色表
 * </p>
 *
 * @author wangliang
 * @since 2023-07-17
 */
@ApiModel(value = "SysRole对象", description = "角色表")
public class SysRole extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "机构id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long orgId;

    @ApiModelProperty(value = "角色名称")
    private String name;

    @ApiModelProperty(value = "是否启用，0：停用，1：启用")
    private Boolean enable;

    @ApiModelProperty(value = "角色类别，ADMIN：超级管理员，PMO：总负责人，BUSSINESS：业务线负责人，REGION_MANAGER：大区经理，REGION_COORDINATOR：区域协调人，EFFECT_ENGINEER：实施工程师，ASSISTANT_ENGINEER：助理工程师，QA：QA，CUSTOM：技术客服，DEFINED：自定义")
    private RoleTypeEnum type;

    @ApiModelProperty(value = "是否系统内置角色，1：是，0：不是")
    private Boolean defaultRole;

    @ApiModelProperty(value = "角色说明")
    private String interpret;

    @JsonSerialize(using = ToStringSerializer.class)
    @TableField(exist = false)
    @NotEmpty(message = "权限集合不能为空")
    private List<Long> privilegeIds;

    public SysRole() {

    }

    public SysRole(SysRolePrivilegeParam sysRolePrivilegeParams) {
        if (Objects.nonNull(sysRolePrivilegeParams.getId())) {
            setId(sysRolePrivilegeParams.getId());
        } else {
            setId(SystemConstant.getDbUuid());
        }
        this.name = sysRolePrivilegeParams.getName();
        this.type = RoleTypeEnum.DEFINED;
        this.defaultRole = false;
        this.interpret = RoleTypeEnum.DEFINED.getTitle();
        this.privilegeIds = sysRolePrivilegeParams.getPrivilegeIds();
    }

    public List<Long> getPrivilegeIds() {
        return privilegeIds;
    }

    public void setPrivilegeIds(List<Long> privilegeIds) {
        this.privilegeIds = privilegeIds;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public RoleTypeEnum getType() {
        return type;
    }

    public void setType(RoleTypeEnum type) {
        this.type = type;
    }

    public Boolean getDefaultRole() {
        return defaultRole;
    }

    public void setDefaultRole(Boolean defaultRole) {
        this.defaultRole = defaultRole;
    }

    public String getInterpret() {
        return interpret;
    }

    public void setInterpret(String interpret) {
        this.interpret = interpret;
    }
}
