package com.zhongshu.card.server.core.domain.org;

import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.client.type.RoleType;
import com.zhongshu.card.server.core.domain.base.SuperMain;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Set;

/**
 * @author TRX
 * @date 2024/5/30
 */
@Data
@Document
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Builder
public class Role extends SuperMain {

    @Schema(description = "名称")
    private String name;

    @Schema(description = "角色编码")
    private String code;

    @Schema(description = "角色类型: 系统内置、自定义")
    private RoleType roleType;

    @Schema(description = "角色主体类型，如：项目、机构、学校")
    private AuthType authType;

    @Schema(description = "是否管理角色，主要是给项目管理员，默认绑定一个角色用 ")
    @Indexed
    private Boolean isAdmin = Boolean.FALSE;

    @Schema(description = "是否是游客角色")
    private Boolean isVisitor = Boolean.FALSE;

    @Schema(description = "角色权限列表")
    @Indexed
    private Set<String> auth;

    @Schema(description = "权限执行的角色组id")
    @Indexed
    private String roleGroupId;

    @Schema(description = "权限中心的角色ID")
    private String roleId;

    @Schema(description = "操作人")
    @DBRef(lazy = true)
    private UserAccount creator;

    @Schema(description = "状态")
    private DataState state = DataState.Enable;

    /**
     * 构建角色
     *
     * @param id
     * @return
     */
    public static Role build(String id) {
        Role role = new Role();
        role.setId(id);
        return role;
    }
}
