import mongoose from 'mongoose';
import { generateId } from '../../utils.js';

const fileSchema = new mongoose.Schema(
  {
    _reference: { type: String, default: () => generateId()() },
    name: { required: true, type: String },
    type: { required: true, type: String },
    extension: { required: true, type: String },
    size: { required: false, type: Number },
    metaData: { required: false, type: Object },
  },
  { timestamps: true }
);

fileSchema.virtual('id').get(function () {
  return this._id;
});

fileSchema.set('toJSON', { virtuals: true });

export const fileModel = mongoose.model('file', fileSchema);
