import { Task } from '../../../repositories/tasks/entity/task.entity';
import { UserGroup } from '../../../repositories/user_groups/entity/user_group.entity';
import { User } from '../../../repositories/users/entity/user.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  JoinColumn,
  OneToOne,
  ManyToOne,
} from 'typeorm';

@Entity({ name: 'checkout_permission' })
export class CheckoutPermission {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({})
  task_id: number;

  @Column({ nullable: true })
  user_id?: number;

  @Column({ nullable: true })
  user_group_id?: number;

  @OneToOne(() => User, (user) => user.id)
  @JoinColumn({ name: 'user_id' })
  user?: User;

  @OneToOne(() => UserGroup, (group) => group.id)
  @JoinColumn({ name: 'user_group_id' })
  user_group?: UserGroup;

  @ManyToOne(() => Task, (task) => task.id)
  @JoinColumn({ name: 'task_id' })
  task?: Task;
}
