/**
 * 费率标准库数据模型
 *
 * @author CaiAoLin
 * @date 2017/8/30
 * @version
 */
import mongoose from "mongoose";

let Schema = mongoose.Schema;
let collectionName = 'std_fee_rate_libs';
const oprSchema = require('../all_schemas/opr_schema');

let optionSchema = new Schema({
    name:String,
    value:String,
    selected:Boolean
}, {_id: false});
let subRecord = new Schema({
    ID:Number,
    name:String,
    amount: Number,//倍数
    value: Number,
}, {_id: false});

let recordSchema = new Schema({
    ID:Number,
    name:String,
    editable:Boolean,
    step: Number,//每增加的步数
    amount: Number,//倍数
    value: Number,
    subList:[subRecord],
    optionList:[optionSchema]
}, {_id: false});

let valueMapSchema = new Schema({
    ID:String,
    value:Number
}, {_id: false});

let subFeeRatesSchema = new Schema({
    recodes :[recordSchema],
    valueMaps:[valueMapSchema],
}, {_id: false});

let ratesSchema = new Schema({
    ID: Number,
    ParentID: Number,
    name: String,
    rate: Number,
    memo: String,
    sum:Boolean,
    subFeeRate:subFeeRatesSchema
}, {_id: false});

let modelSchema = {
    // 自增id
    ID: String,
    // 工程所在地
    region: String,
    // 标准名称
    libName: String,
    //编办ID
    compilationId: {
        type: String,
        index: true
    },
    compilationName:String,
    // 费率数据
    rates: {type:[ratesSchema],default:[]},
    creator: String,
    createDate: Number,
    recentOpr: [oprSchema]
};

 mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));

