import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Types } from 'mongoose';
import { ReactionType } from '../../../common/enums/reaction-type.enum';

export type LikeDocument = HydratedDocument<Like>;

@Schema({ timestamps: true, versionKey: false })
export class Like {
  @Prop({ type: Types.ObjectId, required: true, index: true })
  userId!: Types.ObjectId;

  @Prop({ type: Types.ObjectId, required: true, index: true })
  targetId!: Types.ObjectId;

  @Prop({ required: true, enum: ['post', 'comment'] })
  targetType!: 'post' | 'comment';

  @Prop({ type: String, enum: Object.values(ReactionType), default: ReactionType.LIKE, index: true })
  reactionType!: ReactionType;
}

export const LikeSchema = SchemaFactory.createForClass(Like);
LikeSchema.index({ userId: 1, targetId: 1, targetType: 1 }, { unique: true });
