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

let Schema = mongoose.Schema;
let collectionName = 'std_fee_rate_libs';

let optionSchema = new Schema({
    name:String,
    value:String,
    selected:Boolean
}, {_id: false});

let recordSchema = new Schema({
    ID:Number,
    name:String,
    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,
    subFeeRate:subFeeRatesSchema
}, {_id: false});

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

let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
export {model as default, collectionName as collectionName};
