/**
 * Created by vian on 2017/3/22.
 */

let billsLibDao = require("./../models/bills_lib_interfaces");
let callback = function(req, res, err, message, data){
    res.json({error: err, message: message, data: data});
};
let logger = require('../../../logs/log_helper').logger;

module.exports = {
    copyStdBillsLib: async function (req, res) {
        try {
            const data = JSON.parse(req.body.data);
            const userName = req.session.managerData.username;
            const libName = data.libName;
            const libId = data.libId;
            const newLibData = await billsLibDao.copyLib(userName, libName, libId);
            callback(req, res, 0, 'copyLib success', [newLibData]);
        } catch (err) {
            callback(req, res, 1, 'copyLib fail', null);
        }
    },
    getMaxNumber: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.getMaxNumber(data, function(err, message, maxNumber){
            callback(req, res, err, message, maxNumber);
        });
    },
    getABillsLib: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.getABillsLib(data, function(err, message, data){
            callback(req, res, err, message, data);
        });
    },
    getStdBillsLib: function(req, res){
        billsLibDao.getStdBillsLib(function(err, message, stdBillsLib){
            callback(req, res, err, message, stdBillsLib );
        });
    },
    createStdBillsLib: function(req, res){
        let data = JSON.parse(req.body.data);
         billsLibDao.createStdBillsLib(data, function(err, message, info){
            callback(req, res, err, message, info);
         });
    },
    deleteStdBillsLib: function(req, res){
        let data = JSON.parse(req.body.data);
        logger.info(`deleteBillsLib ${req.ip}`);
        billsLibDao.deleteStdBillsLib(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    renameStdBillsLib: function(req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.renameStdBillsLib(data, function (err, message) {
            callback(req, res, err ,message, null);
        });
    },
    getStdBillsLibName: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.getStdBillsLibName(data.billsLibId, function(err, message, info){
            callback(req, res, err, message, info);
        });
    },
    getCurrentUniqId: function(req, res){
        billsLibDao.getCurrentUniqId(function(err, message, id){
            callback(req, res, err, message, id);
        });
    },
    getBills: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.getBills(data.billsLibId, function(err, message, bills){
            callback(req, res, err, message, bills);
        });
    },
    createBills: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.createBills(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    upMove: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.upMove(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    downMove: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.downMove(data, function (err, message) {
            callback(req, res, err, message, null);
        })
    },
    upLevel: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.upLevel(data, function(err, message){
            callback(req, res, err, message, null);
        })
    },
    downLevel: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.downLevel(data, function (err, message) {
            callback(req, res, err, message, null)
        })
    },
    updatePNId: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.updatePNId(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    updateSectionInfo: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.updateSectionInfo(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    updateBills: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.updateBills(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    removeTotal: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.removeTotal(data, function (err, message) {
            callback(req, res, err, message, null);
        })
    },
    updateSerialNo: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.updateSerialNo(data, function (err, message) {
            callback(req, res, err, message, null);
        });
    },
    updateBillsArr: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.updateBillsArr(data, function(err, message){
           callback(req, res, err, message, null);
        });
    },
    pasteBills: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.pasteBills(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    updateRecharge: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.updateRecharge(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    pasteRel: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.pasteRel(data, function(err, message, datas){
            callback(req, res, err, message, datas);
        });
    },
    deleteBills: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.deleteBills(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    isUsed: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.isUsed(data, function (err, message, datas) {
            callback(req, res, err, message, datas);
        });
    },
    getJobContent: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.getJobContent(data, function(err, message, jobs){
            callback(req, res, err, message, jobs);
        });
    },
    createJobContent: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.createJobContent(data, function(err, message, id){
            callback(req, res, err, message, id);
        });
    },
    updateJobContent: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.updateJobContent(data, function(err, message, id){
            callback(req, res, err, message, id);
        });
    },
    updateValue: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.updateValue(data, function(err, message){
            callback(req, res, err, message, null);
        })
    },
    deleteJobContent: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.deleteJobContent(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    pasteJobs: function (req, res) {
        let data = JSON.parse(req.body.data);
        billsLibDao.pasteJobs(data, function(err, message, datas){
            callback(req, res, err, message, datas);
        });
    },
    edCreateJob: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.edCreateJob(data, function(err, message, id){
            callback(req, res, err, message, id);
        })
    },
    edUpdateJob: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.edUpdateJob(data, function(err, message, id){
            callback(req, res, err, message, id);
        })
    },
    getItemCharacter: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.getItemCharacter(data, function(err, message, items){
            callback(req, res, err, message, items);
        });
    },
    createItemCharacter: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.createItemCharacter(data, function(err, message, id){
            callback(req, res, err, message, id);
        });
    },
    updateItemCharacter: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.updateItemCharacter(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    deleteItemCharacter: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.deleteItemCharacter(data, function(err, message){
            callback(req, res, err, message, null);
        });
    },
    pasteItems: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.pasteItems(data, function(err, message, datas){
            callback(req, res, err, message, datas);
        });
    },
    pasteValues: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.pasteValues(data, function(err, message, datas){
            callback(req, res, err, message, datas);
        });
    },
    edCreateItem: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.edCreateItem(data, function(err, message, id){
            callback(req, res, err, message, id);
        })
    },
    edUpdateItem: function(req, res){
        let data = JSON.parse(req.body.data);
        billsLibDao.edUpdateItem(data, function(err, message, id){
            callback(req, res, err, message, id);
        })
    }
}

