'use strict';

module.exports = app => {

    // session验证中间件
    const sessionAuth = app.middlewares.sessionAuth();
    // 创建时间自动填充中间件
    const datetimeFill = app.middlewares.datetimeFill();
    // 项目管理员判断中间件
    const projectManagerCheck = app.middlewares.projectManagerCheck();

    // 登入登出相关
    app.get('/login', 'loginController.index');
    app.get('/', 'loginController.index');
    app.get('/logout', 'loginController.logout');
    app.post('/login', 'loginController.login');

    // 用户信息初始化相关
    app.get('/boot', sessionAuth, 'bootController.index');
    app.post('/boot', sessionAuth, 'bootController.boot');

    // 控制面板相关
    app.get('/dashboard', sessionAuth, 'dashboardController.index');

    // 项目相关
    app.get('/project/info', sessionAuth, 'projectController.info');
    app.get('/project/account', sessionAuth, projectManagerCheck, 'accountController.index');
    app.post('/project/account/permission/:accountId', sessionAuth, projectManagerCheck, 'accountController.savePermission');
    app.get('/project/account/enable/:accountId', sessionAuth, projectManagerCheck, 'accountController.enable');
    app.get('/project/account/disable/:accountId', sessionAuth, projectManagerCheck, 'accountController.enable');
    app.get('/project/switch/:projectId', sessionAuth, projectManagerCheck, 'projectController.switchProject');
    app.post('/project/info', sessionAuth, 'projectController.saveInfo');

    // 台账管理相关
    app.get('/ledger/explode', sessionAuth, 'ledgerController.explode');
    app.post('/ledger/get-children', sessionAuth, 'ledgerController.getChildren');
    app.post('/ledger/base-operation', sessionAuth, 'ledgerController.baseOperation');
    app.post('/ledger/update', sessionAuth, 'ledgerController.update');
    app.post('/ledger/update-info', sessionAuth, 'ledgerController.updateInfo');
    app.post('/ledger/paste-block', sessionAuth, 'ledgerController.pasteBlock');
    app.post('/ledger/add-by-std', sessionAuth, 'ledgerController.addFromStandardLib');
    app.post('/ledger/batch-insert', sessionAuth, 'ledgerController.batchInsert');

    app.get('/ledger/change', sessionAuth, 'ledgerController.change');
    app.get('/ledger/index', sessionAuth, 'ledgerController.index');

    // 台账审批相关
    app.get('/ledger/audit', sessionAuth, 'ledgerAuditController.index');
    app.post('/ledger/audit/add', sessionAuth, 'ledgerAuditController.add');
    app.post('/ledger/audit/delete', sessionAuth, 'ledgerAuditController.remove');
    app.post('/ledger/audit/start', sessionAuth, 'ledgerAuditController.start');
    app.post('/ledger/audit/check', sessionAuth, 'ledgerAuditController.check');
    app.post('/ledger/audit/addContent', sessionAuth, 'ledgerAuditController.addContent');
    app.post('/ledger/audit/getContent', sessionAuth, 'ledgerAuditController.getContent');

    // 签约清单
    app.post('/deal/get-data', sessionAuth, 'dealBillsController.getData');
    app.post('/deal/upload-excel', sessionAuth, 'dealBillsController.loadExcel');
    app.get('/deal/download/:file', sessionAuth, 'dealBillsController.download');

    // 个人账号相关
    app.get('/profile/info', sessionAuth, 'profileController.info');
    app.post('/profile/save', sessionAuth, 'profileController.saveBase');
    app.post('/profile/password', sessionAuth, 'profileController.modifyPassword');
    app.post('/profile/code', sessionAuth, 'profileController.getCode');
    app.post('/profile/bind', sessionAuth, 'profileController.bindMobile');

    // 标段管理相关
    app.get('/tender', sessionAuth, 'tenderController.index');
    app.post('/tender/add', sessionAuth, datetimeFill, 'tenderController.add');
    app.get('/tender/switch/:tenderId', sessionAuth, 'tenderController.switchTender');
    app.post('/tender/save', sessionAuth, datetimeFill, 'tenderController.save');
    app.post('/tender/delete', sessionAuth, datetimeFill, 'tenderController.delete');

    // 计量管理相关
    app.get('/measure/middle', sessionAuth, 'measureController.middle');
    app.get('/measure/stage', sessionAuth, 'measureController.stage');

    //标准库相关
    app.post('/std/bills/get-data', sessionAuth, 'stdBillsController.getData');
    app.post('/std/bills/get-children', sessionAuth, 'stdBillsController.getChildren');
    app.post('/std/chapter/get-data', sessionAuth, 'stdChapterController.getData');
    app.post('/std/chapter/get-children', sessionAuth, 'stdChapterController.getChildren');

    // 查询
    app.post('/search/user', sessionAuth, 'projectController.searchAccount');
};
