import { FunctionPermission } from '@/modules/authorization/decorators/has-feature.decorator';
import { Column, Entity, ManyToMany, OneToMany } from 'typeorm';
import { CoreEntity } from './core/core-entity';
import { ResourcePermission } from './resource-permission.entity';
import { Role } from './role.entity';

@Entity('permissions')
export class Permission extends CoreEntity {
  @Column({ type: 'varchar', unique: true })
  permission_code: FunctionPermission;

  @Column()
  description: string;

  @ManyToMany(() => Role, (role) => role.permissions)
  roles: Role[];

  @OneToMany(() => ResourcePermission, (rp) => rp.permission)
  resource_permissions: ResourcePermission[];
}
