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

export type ResumeDocument = Resume & Document

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

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

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

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

  @Prop({ default: 1 })
  version: number

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

  @Prop({ default: false })
  paidDownload: boolean

  readonly createdAt?: Date
  readonly updatedAt?: Date
}

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