import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Types } from 'mongoose';
import { User } from '../../users/schemas/user.schema';

export type BlockDocument = HydratedDocument<Block>;

@Schema({ timestamps: true, versionKey: false })
export class Block {
  @Prop({ type: Types.ObjectId, ref: User.name, required: true, index: true })
  blockerId!: Types.ObjectId;

  @Prop({ type: Types.ObjectId, ref: User.name, required: true, index: true })
  blockedId!: Types.ObjectId;
}

export const BlockSchema = SchemaFactory.createForClass(Block);
BlockSchema.index({ blockerId: 1, blockedId: 1 }, { unique: true });
