var Models = require('../models/models.schema');
var Make = require('../models/make.schema');
exports.saveModel = function (req, res) {
    var newModels = [{
        "value": "ILX",
        "make_id": "ford",
        "name": "ILX",
        "checked": false
    },
    {
        "value": "MDX",
        "make_id": "ford",
        "name": "MDX",
        "checked": false
    },
    {
        "value": "ILX",
        "make_id": "acura",
        "name": "ILX",
        "checked": false
    },
    {
        "value": "MDX",
        "make_id": "acura",
        "name": "MDX",
        "checked": false
    }];
    var error = false;
    newModels.forEach(function (newModel) {
        var newModelObj = new Models(newModel);
        newModelObj.save(function (err) {
            if (err) {
                throw err;
                error = true;
            };
        });
    });
    if (error) {
        res.status(401).sendStatus({ success: false, message: "error in inserting Models!" });
    } else {
        res.json({ sucess: true, message: "Models saved successfully!" });

    }
}

exports.getAllModels = function (req, res) {
    Models.find(function (err, data) {
        if (err) {
            res.status(401).sendStatus({ success: false, message: "error in finding models details!" });
        }
        console.log(data);
        res.status(200).json({ success: true, data: data });
    });
}


