import mongoose from 'mongoose';
import SampleModel from './sample';
import MeasurementTemplateModel from './measurement_template';
import db from '../db';



const MeasurementSchema = new mongoose.Schema({
  sample_id: {type: mongoose.Schema.Types.ObjectId, ref: SampleModel},
  values: mongoose.Schema.Types.Mixed,
  measurement_template: {type: mongoose.Schema.Types.ObjectId, ref: MeasurementTemplateModel},
  status: String
}, {minimize: false});

// changelog query helper
MeasurementSchema.query.log = function <Q extends mongoose.DocumentQuery<any, any>> (req) {
  db.log(req, this);
  return this;
}
MeasurementSchema.index({sample_id: 1});
MeasurementSchema.index({measurement_template: 1});

export default mongoose.model<any, mongoose.Model<any, any>>('measurement', MeasurementSchema);