import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('ai_interview_schedules')
export class AiInterviewSchedules {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'int' })
  application_id: number; // Links to job_applications

  @Column({ type: 'int' })
  job_id: number; // convenience copy of job_posts.id

  @Column({ type: 'int', nullable: true })
  interview_id: number; // pointer to user_ai_interviews

  @Column({ type: 'int' })
  requester_user_id: number; // master users.id of the requesting account

  @Column({ type: 'int', nullable: true })
  seeker_id: number;

  @Column({ type: 'datetime', nullable: true })
  scheduled_at: Date; // start datetime

  @Column({ type: 'datetime', nullable: true })
  requested_end: Date; // computed end datetime

  @Column({
    type: 'enum',
    enum: ['instant', 'scheduled'],
    default: 'scheduled',
  })
  mode: 'instant' | 'scheduled';

  @Column({
    type: 'enum',
    enum: [
      'requested',
      'approved',
      'rejected',
      'cancelled',
      'expired',
      'scheduled',
      'in_progress',
      'completed',
      'no_show',
    ],
    default: 'requested',
  })
  status: string;

  @Column({ type: 'varchar', length: 64, nullable: true })
  schedule_token: string; // Secure token

  @Column({ type: 'boolean', default: false })
  reminder_1day_sent: boolean;

  @Column({ type: 'boolean', default: false })
  reminder_1hour_sent: boolean;

  @Column({ type: 'int', nullable: true })
  recruiter_id: number; // Recruiter who actioned the request

  @Column({ type: 'text', nullable: true })
  response_note: string; // Recruiter comment

  @Column({ type: 'json', nullable: true })
  questions_list: number[]; // Locked list of Question IDs for this interview

  @Column({ type: 'json', nullable: true })
  answers: Record<string, any>; // Store answers { questionQuestionId: optionId }

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  requested_at: Date; // Request creation timestamp

  @Column({ type: 'datetime', nullable: true })
  responded_at: Date; // Response timestamp

  @Column({ type: 'datetime', nullable: true })
  started_at: Date;

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

  @Column({ type: 'json', nullable: true })
  submission_meta: { type?: string; reason?: string; timestamp?: Date };

  @CreateDateColumn({ type: 'timestamp' })
  created_at: Date;

  @UpdateDateColumn({ type: 'timestamp' })
  updated_at: Date;
}
