import { bigintTransformer } from '../../../common/entity';
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,
  ManyToOne,
} from 'typeorm';

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

  @Column({})
  task_id: number;

  @Column({ nullable: true, type: 'bigint', transformer: bigintTransformer })
  user_id: number | null;

  @Column({ nullable: true, type: 'bigint', transformer: bigintTransformer })
  user_group_id: number | null;

  @ManyToOne(() => User, (user) => user.id)
  @JoinColumn({ name: 'user_id' })
  user: User | null;

  @ManyToOne(() => UserGroup, (group) => group.id)
  @JoinColumn({ name: 'user_group_id' })
  user_group: UserGroup | null;

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