package cn.lihongjie.coal.role.entity;

import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.permission.entity.PermissionEntity;
import cn.lihongjie.coal.user.entity.UserEntity;

import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToMany;

import lombok.Data;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.Comment;

import java.util.List;

@Entity
@Data
@Cacheable

@jakarta.persistence.Table(indexes = @jakarta.persistence.Index(name ="idx_role_org_id", columnList = "organization_id"))

public class RoleEntity extends OrgCommonEntity {

    @Comment("是否为系统默认角色")
    private Boolean isSysDefault = false;

    @Comment("是否为机构管理员默认角色")
    private Boolean isOrgAdmin = false;

    @ManyToMany(mappedBy = "roles")
    @Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
    private List<UserEntity> users;

    @ManyToMany
    @Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
    private List<PermissionEntity> permissions;
}