import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import type { AssessmentQuestion } from './assessment-question.entity';

@Entity('assessment_answers')
export class AssessmentAnswer {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'question_id' })
  questionId: string;

  @ManyToOne(
    'AssessmentQuestion',
    (question: AssessmentQuestion) => question.answers,
    { onDelete: 'CASCADE' },
  )
  @JoinColumn({ name: 'question_id' })
  question: AssessmentQuestion;

  @Column({ type: 'text', name: 'user_answer' })
  userAnswer: string;

  @Column({ type: 'float', nullable: true })
  score: number;

  @Column({ type: 'text', nullable: true })
  feedback: string;

  @Column({ type: 'boolean', name: 'is_follow_up', default: false })
  isFollowUp: boolean;

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

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