import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
  OneToMany,
} from 'typeorm';
import type { AssessmentSession } from './assessment-session.entity';
import type { AssessmentAnswer } from './assessment-answer.entity';

@Entity('assessment_questions')
export class AssessmentQuestion {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'session_id' })
  sessionId: string;

  @ManyToOne(
    'AssessmentSession',
    (session: AssessmentSession) => session.questions,
    { onDelete: 'CASCADE' },
  )
  @JoinColumn({ name: 'session_id' })
  session: AssessmentSession;

  @Column({ type: 'text', name: 'question_text' })
  questionText: string;

  @Column({ type: 'simple-json', name: 'key_points', nullable: true })
  keyPoints: string[];

  @Column({ type: 'varchar', nullable: true })
  difficulty: string;

  @OneToMany('AssessmentAnswer', (answer: AssessmentAnswer) => answer.question)
  answers: AssessmentAnswer[];

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;
}
