import { AudioOptionItem } from '../../../repositories/audio_option_items/entity/audio_option_item.entity';
import { AudioFile } from '../../../repositories/audio_files/entity/audio_file.entity';
import { User } from '../../../repositories/users/entity/user.entity';
import { TemplateFile } from '../../template_files/entity/template_file.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  OneToOne,
  JoinColumn,
  OneToMany,
  ManyToOne,
} from 'typeorm';

@Entity({ name: 'tasks' })
export class Task {
  @PrimaryGeneratedColumn()
  id: number;
  @Column()
  job_number: string;
  @Column()
  account_id: number;
  @Column({ nullable: true })
  is_job_number_enabled?: boolean;
  @Column()
  audio_file_id: number;
  @Column()
  status: string;
  @Column({ nullable: true })
  typist_user_id?: number;
  @Column()
  priority: string;
  @Column({ nullable: true })
  template_file_id?: number;
  @Column({ nullable: true })
  started_at?: Date;
  @Column({ nullable: true })
  finished_at?: Date;
  @Column({})
  created_at: Date;
  @OneToOne(() => AudioFile, (audiofile) => audiofile.task)
  @JoinColumn({ name: 'audio_file_id' })
  file?: AudioFile;
  @OneToMany(() => AudioOptionItem, (option) => option.task)
  option_items?: AudioOptionItem[];
  @OneToOne(() => User, (user) => user.id)
  @JoinColumn({ name: 'typist_user_id' })
  typist_user?: User;
  @ManyToOne(() => TemplateFile, (templateFile) => templateFile.id)
  @JoinColumn({ name: 'template_file_id' })
  template_file?: TemplateFile;
}
