import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  OneToMany,
} from 'typeorm';
import { CandidateAnswer } from '../../candidate_answers/entities/candidate_answers.entity';

export enum AttemptStatus {
  IN_PROGRESS = 'in_progress',
  COMPLETED = 'completed',
  ABANDONED = 'abandoned',
}

@Entity('mock_test_attempts')
export class MockTestAttempts {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  candidate_id: number;

  @Column()
  role_id: number;

  @CreateDateColumn()
  started_at: Date;

  @Column({ type: 'timestamp', nullable: true })
  completed_at: Date;

  @Column({ default: 0 })
  total_questions: number;

  @Column({ default: 0 })
  correct_answers: number;

  @Column({ type: 'decimal', precision: 5, scale: 2, default: 0.0 })
  score: number;

  @Column({
    type: 'enum',
    enum: AttemptStatus,
    default: AttemptStatus.IN_PROGRESS,
  })
  status: AttemptStatus;

  @Column('json', { nullable: true })
  metadata: any;

  @OneToMany(() => CandidateAnswer, (answer) => answer.attempt)
  answers: CandidateAnswer[];
}
