/**
 * Created by CSL on 2017-03-29.
 */

let mongoose = require('mongoose');
let Schema = mongoose.Schema;
let deleteSchema = require('../all_schemas/delete_schema');
// {ID:1,name:'工程分类',optionList:[{name:'一类工程',value:1,selected:true},{name:'二类工程',value:2,selected:false},{name:'三类工程',value:3,selected:false},{name:'四类工程',value:4,selected:false}]},
let optionSchema = new Schema({
    name:String,
    value:String,
    selected:Boolean
},{versionKey:false,_id: false})

let recordSchema = new Schema({
    ID:Number,
    name:String,
    optionList:[optionSchema]
},{versionKey:false,_id: false})

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


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

let feeRatesSchema = new Schema({
    ID: String,
    rates: [ratesSchema],
    deleteInfo: deleteSchema
},{versionKey:false});

mongoose.model('fee_rates', feeRatesSchema, 'fee_rates');


let feeRateFileSchema = new Schema({
    ID: String,
    rootProjectID:Number,//顶层项目ID
    userID:String,
    name:String,
    libID: String,
    libName: String,
    feeRateID:String,//关联的费率ID
    deleteInfo: deleteSchema
},{versionKey:false});

mongoose.model('fee_rate_file', feeRateFileSchema, 'fee_rate_file');
