import * as asyncHandler from 'express-async-handler';
import * as userBiz from '../biz/fuHuqQi/user';
import * as baseBiz from '../biz/fuHuqQi/base';
import * as enterpriseBiz from '../biz/enterprise/enterprise';
import * as financingBiz from '../biz/enterprise/financing';
import * as guanWeiHuiBiz from '../biz/guanWeiHui/user';
import { checkParamaterType, checkReqParam } from '../util/tools';
import { BizError } from '../util/bizError';
import { ERRORENUM } from '../config/errorEnum';
import { monthTableList } from '../biz/fuHuqQi/month';


export function setRouter(httpServer) {
    // /**登录 */
    httpServer.post('/admin/login', asyncHandler(login));
    // /** 孵化器*/
    httpServer.post('/admin/fuhuaqi/baselist', asyncHandler(fuHuaQiBaseList));
    httpServer.post('/admin/fuhuaqi/monthoccupancyrate', asyncHandler(getMonthList));
    httpServer.post('/admin/fuhuaqi/userlist', asyncHandler(getFuHuaQiUserList));
    httpServer.post('/admin/fuhuaqi/updatestate', asyncHandler(updateState));
    httpServer.post('/admin/fuhuaqi/adduser',asyncHandler(addUser));
    /**企业 */
    httpServer.post('/admin/enterprise/list', asyncHandler(getEnterpriseList));
    httpServer.post('/admin/enterprise/financinglist', asyncHandler(getFinancingList));
    httpServer.post('/admin/enterprise/affiliationfuhuaqi',asyncHandler(affiliationFuHuaQi));
    
}
    

/**
 * 管理后台登录
 * @param req 
 * @param res 
 */
async function login(req, res) {
    let reqConf = {loginId:'String', pwd:'String'};
    let {loginId, pwd} = checkReqParam(reqConf, req.body);

    let userInfo = await guanWeiHuiBiz.login(loginId, pwd);
    res.success(userInfo);
}


/**
 * 孵化器基本信息列表
 * @param req 
 * @param res 
 */
async function fuHuaQiBaseList(req, res) {
    let reqConf = {lv: 'Number', institutionalNature: 'Number', industry: 'Number', page: 'Number' };
    let {lv, institutionalNature, industry, page} = checkParamaterType(reqConf, req.body);
    
    let result = await baseBiz.fuHuaQiBaseList(lv, institutionalNature, industry, page);

    res.success(result);
}


/**
 * 后台管理  获取月度出租率信息列表
 * @param req 
 * @param res 
 */
async function getMonthList(req, res) {
    let  reqConf = {state: 'Number', year: 'Number', month: 'Number', page: 'Number'};
    let { state, year, month, page } = checkParamaterType(reqConf, req.body);
    
    let result = await monthTableList(state, year, month, page);
    res.success(result);
}


/**
 * 后台管理 获取孵化器账号信息列表 
 * @param req 
 * @param res 
 */
 async function getFuHuaQiUserList(req, res) {
    let reqConf = {operationName: 'String', page: 'Number' };
    let { operationName, page } = checkParamaterType(reqConf, req.body);

    let result = await userBiz.fuHuaQiUserList(operationName, page);
    res.success(result);
}


/**
 * 后台管理 获取融资企业信息列表 
 * @param req 
 * @param res
 */
 async function getFinancingList(req, res) {
    let reqConf = {monthData: 'String', fuHuaQiName: 'String', fuHuaQiInvestment: 'Number', industry: '[Number]', page: 'Number' };
    let {monthData, fuHuaQiName, industry, fuHuaQiInvestment, page} = checkParamaterType(reqConf, req.body);

    let result = await financingBiz.financingList(monthData, fuHuaQiName, industry, fuHuaQiInvestment, page);
    res.success(result);
}


/**
 * 后台管理 获取在孵企业信息列表 
 * @param req 
 * @param res 
 */
 async function getEnterpriseList(req, res) {
    let reqConf = {time: 'Number', fuHuaQiUscc: 'String', industry: '[Number]', isNaturalPersonHolding: 'Number', page: 'Number' };
    let { time, fuHuaQiUscc, industry, isNaturalPersonHolding, page } = checkParamaterType(reqConf, req.body);

    let result = await enterpriseBiz.enterpriseList(time, fuHuaQiUscc, industry, isNaturalPersonHolding, page);
    res.success(result);
}


/**
 * 后台管理 修改孵化器账号状态 
 * @param req 
 * @param res 
 */
 async function updateState(req, res) {
    let reqConf = {userState: 'Boolean', uscc: 'String' };
    let { userState, uscc } = checkReqParam(reqConf, req.body);

    let result = await userBiz.updateState(uscc, userState);
    res.success(result);
}

/**
 * 后台管理 新增孵化器账号
 * @param req 
 * @param res 
 */
async function addUser(req, res) {
    let reqConf = {form: 'Object' };
    let { form } = checkReqParam(reqConf, req.body);

    let result = await userBiz.addUser(form);
    res.success(result);
} 


/**
 * 所属孵化器
 * @param req 
 * @param res 
 */
async function affiliationFuHuaQi(req, res) {
    let  result = await enterpriseBiz.getAffiliationFuHuaQi();
    res.success(result);
}