'use strict';

module.exports = app => {

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

    // 登入登出相关
    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('/setting/info', sessionAuth, 'settingController.info');
    app.post('/setting/updateinfo/:id', sessionAuth, 'settingController.updateinfo');
    // 账号设置
    app.get('/setting/user', sessionAuth, 'settingController.user');
    // 标段自定义类别
    app.get('/setting/category', sessionAuth, 'settingController.category');
    app.post('/setting/category/add', sessionAuth, 'settingController.addCategory');
    app.post('/setting/category/del', sessionAuth, 'settingController.deleteCategory');
    app.post('/setting/category/update', sessionAuth, 'settingController.updateCategory');
    app.post('/setting/category/value', sessionAuth, 'settingController.setCategoryValue');
    app.post('/setting/category/level', sessionAuth, 'settingController.resetCategoryLevel');

    // 项目相关
    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('/list', sessionAuth, 'tenderController.listInfo');
    // 计量进度
    app.get('/list/progress', sessionAuth, 'tenderController.listProgress');
    // 管理标段
    app.get('/list/manage', sessionAuth, 'tenderController.listManage');
    app.post('/list/add', sessionAuth, 'tenderController.addTender');
    app.post('/list/update', sessionAuth, 'tenderController.updateTender');
    app.post('/list/del', sessionAuth, 'tenderController.deleteTender');
    // 标段概况
    app.get('/tender/:id', sessionAuth, tenderCheck, 'tenderController.tenderInfo');
    app.get('/tender/:id/type', sessionAuth, 'tenderController.tenderType');
    app.post('/tender/:id/save', sessionAuth, tenderCheck, 'tenderController.saveTenderInfo');
    app.post('/tender/rule', sessionAuth, 'tenderController.rule');


    // 台账管理相关
    app.get('/tender/:id/ledger/explode', sessionAuth, tenderCheck, 'ledgerController.explode');
    app.post('/tender/:id/ledger/get-children', sessionAuth, tenderCheck, 'ledgerController.getChildren');
    app.post('/tender/:id/ledger/base-operation', sessionAuth, tenderCheck, 'ledgerController.baseOperation');
    app.post('/tender/:id/ledger/update', sessionAuth, tenderCheck, 'ledgerController.update');
    app.post('/tender/:id/ledger/update-info', sessionAuth, tenderCheck, 'ledgerController.updateInfo');
    app.post('/tender/:id/ledger/paste-block', sessionAuth, tenderCheck, 'ledgerController.pasteBlock');
    app.post('/tender/:id/ledger/add-by-std', sessionAuth, tenderCheck, 'ledgerController.addFromStandardLib');
    app.post('/tender/:id/ledger/batch-insert', sessionAuth, tenderCheck, 'ledgerController.batchInsert');
    app.post('/tender/:id/ledger/explode/upload-excel', sessionAuth, tenderCheck, 'ledgerController.uploadExcel');
    app.get('/tender/:id/ledger/download/:file', sessionAuth, tenderCheck, 'ledgerController.download');
    app.post('/tender/:id/pos', sessionAuth, tenderCheck, 'ledgerController.pos');
    app.post('/tender/:id/pos/update', sessionAuth, tenderCheck, 'ledgerController.posUpdate');
    app.post('/tender/:id/pos/paste', sessionAuth, tenderCheck, 'ledgerController.posPaste');

    app.get('/tender/:id/ledger/change', sessionAuth, tenderCheck, 'ledgerController.change');
    app.get('/tender/:id/ledger/index', sessionAuth, 'ledgerController.index');

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

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

    // 计量台账
    // 期计量
    app.get('/tender/:id/measure/stage', sessionAuth, tenderCheck, 'measureController.stage');
    app.post('/tender/:id/measure/stage/add', sessionAuth, tenderCheck, 'measureController.addStage');
    app.post('/tender/:id/measure/stage/save', sessionAuth, tenderCheck, 'measureController.saveStage');
    // 计量台账 -- 清单汇总
    app.get('/tender/:id/measure/gather', sessionAuth, tenderCheck, 'measureController.gather');
    // 计量台账 -- 审核比较
    app.get('/tender/:id/measure/compare', sessionAuth, tenderCheck, 'measureController.compare');

    // 期计量详细
    // 本期计量台账
    app.get('/tender/:id/measure/stage/:order', sessionAuth, tenderCheck, 'stageController.index');
    app.post('/tender/:id/measure/stage/:order/pos', sessionAuth, tenderCheck, 'stageController.getStagePosData');
    app.post('/tender/:id/measure/stage/:order/update', sessionAuth, tenderCheck, 'stageController.updateStageData');
    // 中间计量
    app.get('/tender/:id/measure/stage/:order/detail', sessionAuth, tenderCheck, 'stageController.detail');
    app.post('/tender/:id/measure/stage/:order/detail/build', sessionAuth, tenderCheck, 'stageController.buildDetailData');
    app.post('/tender/:id/measure/stage/:order/detail/adv', sessionAuth, tenderCheck, 'stageController.setAdvancedConfig');
    app.post('/tender/:id/measure/stage/:order/detail/load', sessionAuth, tenderCheck, 'stageController.loadDetailRelaData');
    app.post('/tender/:id/measure/stage/:order/detail/save', sessionAuth, tenderCheck, 'stageController.saveDetailData');
    app.post('/tender/:id/measure/stage/:order/detail/add-img', sessionAuth, tenderCheck, 'stageController.addCalcImage');
    app.post('/tender/:id/measure/stage/:order/detail/merge-img', sessionAuth, tenderCheck, 'stageController.mergeCalcImage');
    // 合同支付
    app.get('/tender/:id/measure/stage/:order/pay', sessionAuth, tenderCheck, 'stageController.pay');
    // 变更令
    app.get('/tender/:id/measure/stage/:order/change', sessionAuth, tenderCheck, 'stageController.change');
    // 审批
    app.post('/tender/:id/measure/stage/:order/audit/add', sessionAuth, tenderCheck, 'stageController.addAudit');
    app.post('/tender/:id/measure/stage/:order/audit/delete', sessionAuth, tenderCheck, 'stageController.deleteAudit');
    app.post('/tender/:id/measure/stage/:order/audit/start', sessionAuth, tenderCheck, 'stageController.startAudit');
    app.post('/tender/:id/measure/stage/:order/audit/check', sessionAuth, tenderCheck, 'stageController.checkAudit');
    // 清单汇总
    app.get('/tender/:id/measure/stage/:order/gather', sessionAuth, tenderCheck, 'stageController.gather');
    // 审核比较
    app.get('/tender/:id/measure/stage/:order/compare', sessionAuth, tenderCheck, 'stageController.compare');
    app.post('/tender/:id/measure/stage/:order/compare/load', sessionAuth, tenderCheck, 'stageController.compareAuditor');
    // 报表
    app.get('/tender/:id/measure/stage/:order/report', sessionAuth, tenderCheck, 'stageController.report');
    // 变更管理
    app.get('/tender/:id/change', sessionAuth, tenderCheck, 'changeController.index');
    app.get('/tender/:id/change/status/:status', sessionAuth, tenderCheck, 'changeController.status');
    app.post('/tender/:id/change/newCode', sessionAuth, tenderCheck, 'changeController.newCode');
    app.post('/tender/:id/change/add', sessionAuth, tenderCheck, 'changeController.add');
    app.get('/tender/:id/change/:cid/info', sessionAuth, tenderCheck, 'changeController.info');
    app.post('/change/upload/file', sessionAuth, 'changeController.uploadFile');
    app.get('/change/download/file/:id', sessionAuth, 'changeController.downloadFile');
    app.post('/change/delete/file', sessionAuth, 'changeController.deleteFile');

    app.post('/change/save', sessionAuth, 'changeController.save');

    app.post('/change/approval', sessionAuth, 'changeController.approval');

    // 变更单位管理
    app.post('/change/update/company', sessionAuth, 'changeController.updateCompany');

    // 个人账号相关
    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('/measure/wlist', sessionAuth, tenderSelect, 'measureController.list');
    //
    // app.get('/measure/work/:mid', sessionAuth, tenderSelect, 'measureController.work');
    // app.post('/measure/newCode', sessionAuth, 'measureController.newCode');
    // app.post('/measure/add', sessionAuth, 'measureController.addMeasure');
    // app.post('/measure/delete', sessionAuth, 'measureController.deleteMeasure');
    // app.post('/measure/search', sessionAuth, 'measureController.search');
    // app.post('/measure/pos', sessionAuth, 'measureController.pos');
    // app.post('/measure/bills', sessionAuth, 'measureController.bills');
    // app.post('/measure/detail', sessionAuth, 'measureController.measureDetail');
    // app.post('/measure/billsUpdate', sessionAuth, 'measureController.billsUpdate');

    // 中间计量 - 计量审批相关
    // app.get('/measure/alist', sessionAuth, tenderSelect, 'measureAuditController.list');
    // app.get('/measure/audit/:mid', sessionAuth, 'measureAuditController.index');
    // app.post('/measure/audit/add', sessionAuth, 'measureAuditController.add');
    // app.post('/measure/audit/remove', sessionAuth, 'measureAuditController.remove');
    // app.post('/measure/audit/start', sessionAuth, 'measureAuditController.start');
    // app.post('/measure/audit/check', sessionAuth, 'measureAuditController.check');

    // 期计量管理相关
    // app.get('/tender/:id/measure/stage', sessionAuth, tenderCheck, 'stageController.index');
    // app.post('/tender/:id/stage/add', sessionAuth, tenderCheck, 'stageController.add');
    // app.get('/tender/:id/stage/:order/measure', sessionAuth, tenderSelect, 'stageController.stageMeasure');
    // app.get('/tender/:id/stage/:order/deal', sessionAuth, tenderSelect, 'stageController.stageDeal');
    // app.get('/tender/:id/stage/:order/report', sessionAuth, tenderSelect, 'stageController.stageReport');

    // 标准库相关
    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');
};
