const mongoose = require('mongoose')

const schema = {
  _id: false,
  cve_year: String,
  ranges: {
    priority: {
      top_id: {
        type: Number,
        default: 0
      },
      start: {
        type: Number,
        default: 0
      },
      end: {
        type: Number,
        default: 20000
      }
    },
    general: {
      top_id: {
        type: Number,
        default: 20000
      },
      start: {
        type: Number,
        default: 20000
      },
      end: {
        type: Number,
        default: 50000000
      }
    }
  }
}

const CveIdRangeSchema = new mongoose.Schema(schema, { collection: 'Cve-Id-Range' })

CveIdRangeSchema.query.byCveYear = function (cveYear) {
  return this.where({ cve_year: cveYear })
}

const CveIdRange = mongoose.model('Cve-Id-Range', CveIdRangeSchema)
module.exports = CveIdRange
