import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { PolymorphicAuthor } from './core/polymorphic-author';
import { Permission } from './permission.entity';
import { Resource } from './resource.entity';

@Entity('resource_permissions')
export class ResourcePermission extends PolymorphicAuthor {
  @Column()
  resource_id: number;

  @Column()
  permission_id: number;

  @ManyToOne(() => Resource, (resource) => resource.resource_permissions)
  @JoinColumn({ name: 'resource_id' })
  resource: Resource;

  @ManyToOne(() => Permission, (permission) => permission.resource_permissions)
  @JoinColumn({ name: 'permission_id' })
  permission: Permission;
}
