import { Entity, Index, ManyToOne, Unique } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Role } from '../../roles/entities/role.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
import { Admin } from './admin.entity';

@Entity({ tableName: 'admin_roles' })
@Index({ properties: ['admin', 'restaurant'] })
@Index({ properties: ['admin'] })
@Index({ properties: ['restaurant'] })
export class AdminRole extends BaseEntity {
  @ManyToOne(() => Admin)
  admin!: Admin;

  @ManyToOne(() => Role)
  role!: Role;

  @ManyToOne(() => Restaurant, { nullable: true })
  restaurant?: Restaurant;
}
