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

const materialSchema = new mongoose.Schema({
  _reference: { type: String, default: () => generateId()() },
  name: { required: true, type: String },
  url: { required: false, type: String },
  image: { required: false, type: Buffer },
  tags: [{ type: String }],
});

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

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

export const materialModel = mongoose.model('material', materialSchema);
