import mongoose, { Document } from 'mongoose';

import { MODEL_NAMES } from './_models';

const mongooseLeanId = require('../plugins/id.plugin');

export interface IUploadedData {
  sheetId: mongoose.Types.ObjectId;
  order: number;
  data: Object;
}

export interface IUploadedDataDoc extends IUploadedData, Document {
}

export const UploadedDataSchema = new mongoose.Schema(
  {
    sheetId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.uploadedSheets,
      required: true,
    },
    order: {
      type: Number,
      required: true,
    },
    data: mongoose.Schema.Types.Mixed,
    __v: { type: Number, select: false },
  },
  { timestamps: true }
);

UploadedDataSchema.plugin(mongooseLeanId);

export default mongoose.model<IUploadedDataDoc>(MODEL_NAMES.uploadedData, UploadedDataSchema);
