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

export type MediaFileDocument = HydratedDocument<MediaFile>;

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

  @Prop({ required: true })
  url!: string;

  @Prop({ required: true })
  mimeType!: string;

  @Prop({ required: true })
  size!: number;
}

export const MediaFileSchema = SchemaFactory.createForClass(MediaFile);
MediaFileSchema.index({ ownerId: 1, createdAt: -1 });
