import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { Document, Types } from 'mongoose'

export type InterviewDocument = Interview & Document

@Schema({ timestamps: true })
export class Interview {
  @Prop({ type: Types.ObjectId, ref: 'User', required: true })
  userId: Types.ObjectId

  @Prop({ required: true })
  position: string

  @Prop({ default: 'in_progress' })
  status: string

  @Prop({ default: 0 })
  totalScore: number

  @Prop({ default: 0 })
  questionCount: number

  @Prop({ type: [{ role: String, content: String, score: Number }], default: [] })
  messages: { role: string; content: string; score?: number }[]

  @Prop({ default: '' })
  summary: string

  @Prop({ type: [{ word: String, count: Number }], default: [] })
  fillerWords: { word: string; count: number }[]

  @Prop({ default: 0 })
  fillerScore: number

  @Prop({ default: 0 })
  fillerDensity: number

  readonly createdAt?: Date
  readonly updatedAt?: Date
}

export const InterviewSchema = SchemaFactory.createForClass(Interview)
InterviewSchema.index({ userId: 1, createdAt: -1 })
