/**
 * 公共资源路由
 */

import * as asyncHandler from 'express-async-handler';
import { ZLSTATISTYPE, CONTRACTTYPE, RENTTYPE, ZLSTATETYPE, VISITSTATE, VISITENTERPRISETYPE, VISITDEMAND, RESEARCHTYPE, JIASUZIZHI, ENTERPRISECHANGETYPE, ACTIVITYLABEL, FUHUAQILV, INSTITUTIONALNATURE, FUHUAINDUSTRY, INDUSTRY, FUHUAQILNVESTMENTSTYLE, OPERATIONMODEL, TEAM, DEGREE, FINANCINGROUNDS, INSIDESTATE, VIRTUALCAUSE, MOVEOUTTYPE, MOVEOUTCAUSECLIENT, MOVEOUTCAUSENOTCLIENT, MOVEOUTTRACE, ENTERPRISETEAM, LISTINGSITUATION, BUSINESSDATATYPE, COOPERATIONMODE, SPECIALITY, TEACHERLV, ZJBEYONDLAYOUTOPERATIONMODE, CYCXFX, CYCSRBJ, FUHUAQICUSTOMTASKTYPE, ZHONGDIANQIYE } from '../config/enum';
import { selectLabelList } from '../data/label';
import { GUANWEIHUIMANANGENTERPRISELABEL, LABELTYPE, LABELGOAL, FHQSYSTEMLABEL } from '../config/enum/labelEnum';
import { NOTZHIBUTYPEENUM, ZHIBUTYPEENUM } from '../config/enum/dangJianEnum';

export function setRouter(httpServer) {
    httpServer.post('/public/fuhuaqilv', asyncHandler(getFuHuaQiLv));
    httpServer.post('/public/institutionalnature', asyncHandler(getInstitutionalNature));
    httpServer.post('/public/fuhuaqiindustry', asyncHandler(getFuHuaQiIndustry));
    httpServer.post('/public/industry', asyncHandler(getIndustry));
    httpServer.post('/public/investmentstyle', asyncHandler(getFuHuaQiInvestmentStyle));
    httpServer.post('/public/operationmodel', asyncHandler(operationModel));
    httpServer.post('/public/fuhuaqiteam', asyncHandler(fuHuaQiTeam));
    httpServer.post('/public/degree', asyncHandler(degree));
    httpServer.post('/public/financingrounds', asyncHandler(financingRounds));
    /**2.0 */
    httpServer.post('/public/insidestate', asyncHandler(insidestate));
    httpServer.post('/public/virtualcause', asyncHandler(virtualCause));
    httpServer.post('/public/moveouttype', asyncHandler(moveOutType));
    httpServer.post('/public/moveoutcause', asyncHandler(moveOutCause));
    /**2.1 */
    httpServer.post('/public/graduatecause', asyncHandler(graduateCauseType));
    /**2.3 */
    httpServer.post('/public/moveouttrace', asyncHandler(moveOutTrace) );
    /**3.0 */
    httpServer.post('/public/enterpriseteam', asyncHandler(initTeam) );
    httpServer.post('/public/listingsituation', asyncHandler(listingSituation) );
    httpServer.post('/public/businessdatatype', asyncHandler(businessDataType) );
    /**3.1 */
    httpServer.post('/public/cooperationmode', asyncHandler(cooperationMode) );
    httpServer.post('/public/speciality', asyncHandler(speciality) );
    httpServer.post('/public/teacherlv', asyncHandler(teacherLv) );
    httpServer.post('/public/zjbeyondlayoutoperationmode', asyncHandler(zjBeYondLayoutOperationMode) );
    /**4.2 */
    httpServer.post('/public/cycxfx', asyncHandler(cycxfx) );
    httpServer.post('/public/cycsrbj', asyncHandler(cycsrbj) );
    /**6.0 */
    httpServer.post('/public/fuhuaqicustomtasktype', asyncHandler(fuhuaqiCustomTaskType) );
    httpServer.post('/public/enterpriseselectlist', asyncHandler(enterpriseSelectList) );
    httpServer.post('/public/admin/enterprilabelselectlist', asyncHandler(enterpriLabelSelectList) );
    httpServer.post('/public/fuhuaqiselectlist', asyncHandler(fuHuaQiSelectList) );
    /**6.1 */
    httpServer.post('/public/zhibutypeselect', asyncHandler(fuHuaQiZhiBuTypeSelectList) );
    httpServer.post('/public/notzhibutypeselect', asyncHandler(fuHuaQiNotZhiBuTypeSelectList) );


    httpServer.post('/public/zlstatistype', asyncHandler(zlstatistype) );
    httpServer.post('/public/contracttype', asyncHandler(contracttype) );
    httpServer.post('/public/renttype', asyncHandler(renttype) );
    httpServer.post('/public/zlstatetype', asyncHandler(zlstatetype) );
    httpServer.post('/public/visitstate', asyncHandler(visitstate) );
    httpServer.post('/public/visitenterprisetype', asyncHandler(visitenterprisetype) );
    httpServer.post('/public/visitdemand', asyncHandler(visitdemand) );
    httpServer.post('/public/researchtype', asyncHandler(researchtype) );
    httpServer.post('/public/activitylabel', asyncHandler(activitylabel) );

    httpServer.post('/public/enterprisechangetype', asyncHandler(enterprisechangetype) );
    httpServer.post('/public/jiasuzizhi', asyncHandler(jiasuzizhi) );

    httpServer.post('/public/zhongdian', asyncHandler(zhongdian) );
}


async function zhongdian(req, res) {
    let dataList = [];
    for (let key in ZHONGDIANQIYE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ZHONGDIANQIYE[key]});
        }
    }
    res.success({dataList});
}


async function enterprisechangetype(req, res) {
    let dataList = [];
    for (let key in ENTERPRISECHANGETYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ENTERPRISECHANGETYPE[key]});
        }
    }
    res.success({dataList});

}

async function jiasuzizhi(req, res) {
    let dataList = [];
    for (let key in JIASUZIZHI) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:JIASUZIZHI[key]});
        }
    }
    res.success({dataList});

}


async function zlstatistype(req, res) {
    let dataList = [];
    for (let key in ZLSTATISTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ZLSTATISTYPE[key]});
        }
    }
    res.success({dataList});

}

async function contracttype(req, res) {
    let dataList = [];
    for (let key in CONTRACTTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:CONTRACTTYPE[key]});
        }
    }
    res.success({dataList});

}

async function renttype(req, res) {
    let dataList = [];
    for (let key in RENTTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:RENTTYPE[key]});
        }
    }
    res.success({dataList});
}

async function zlstatetype(req, res) {
    let dataList = [];
    for (let key in ZLSTATETYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ZLSTATETYPE[key]});
        }
    }
     res.success({dataList});
}

async function visitstate(req, res) {
    let dataList = [];
    for (let key in VISITSTATE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:VISITSTATE[key]});
        }
    }
     res.success({dataList});
}

async function visitenterprisetype(req, res) {
    let dataList = [];
    for (let key in VISITENTERPRISETYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:VISITENTERPRISETYPE[key]});
        }
   }
    res.success({dataList});
}

async function visitdemand(req, res) {
    let dataList = [];
    for (let key in VISITDEMAND) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:VISITDEMAND[key]});
        }
    }
    res.success({dataList});
}

async function researchtype(req, res) {
    let dataList = [];
    for (let key in RESEARCHTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:RESEARCHTYPE[key]});
        }
    }
    res.success({dataList});
}

async function activitylabel(req, res) {
    let dataList = [];
    for (let key in ACTIVITYLABEL) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ACTIVITYLABEL[key]});
        }
    }
    res.success({dataList});
}


/**
 * 小程序端 创业创始人背景
 * @param req 
 * @param res 
 */
function cycsrbj(req, res) {
    let dataList = [];
    for (let key in CYCSRBJ) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:CYCSRBJ[key]});
        }
    }
    res.success({dataList});
}


/**
 * 小程序端 创业创新方向
 * @param req 
 * @param res 
 */
function cycxfx(req, res) {
    let dataList = [];
    for (let key in CYCXFX) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:CYCXFX[key]});
        }
    }
    res.success({dataList});
}


/**
 * 小程序端 合作方式
 * @param req 
 * @param res 
 */
function cooperationMode(req, res) {
    let dataList = [];
    for (let key in COOPERATIONMODE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:COOPERATIONMODE[key]});
        }
    }
    res.success({dataList});
}

/**
 * 小程序端 专业特长
 * @param req 
 * @param res 
 */
function speciality(req, res) {
    let dataList = [];
    for (let key in SPECIALITY) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            if (keyStr == "科技金融_风险投资_" || keyStr == "科技金融_其他_" || keyStr == "技术专家_法律专家_") {
                keyStr = keyStr.replace("_","(");
                keyStr = keyStr.replace("_",")");
            }
            dataList.push({key:keyStr, value:SPECIALITY[key]});
        }
    }
    res.success({dataList});
}

/**
 * 小程序端 导师等级
 * @param req 
 * @param res 
 */
function teacherLv(req, res) {
    let dataList = [];
    for (let key in TEACHERLV) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:TEACHERLV[key]});
        }
    }
    res.success({dataList});
}


/**
 * 小程序端 张江以外布局运营模式
 * @param req 
 * @param res 
 */
function zjBeYondLayoutOperationMode(req, res) {
    let dataList = [];
    for (let key in ZJBEYONDLAYOUTOPERATIONMODE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ZJBEYONDLAYOUTOPERATIONMODE[key]});
        }
    }
    res.success({dataList});
}


/**
 * 小程序端 经营数据类型
 * @param req 
 * @param res 
 */
function businessDataType(req, res) {
    let dataList = [];
    for (let key in BUSINESSDATATYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:BUSINESSDATATYPE[key]});
        }
    }
    res.success({dataList});
} 


/**
 * 小程序端 上市情况
 * @param req 
 * @param res 
 */
function listingSituation(req, res) {
    let dataList = [];
    for (let key in LISTINGSITUATION) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:LISTINGSITUATION[key]});
        }
    }
    res.success({dataList});
} 



/**
 * 小程序端 企业创始团队
 * @param req 
 * @param res 
 */
function initTeam(req, res) {
    let dataList = [];
    for (let key in ENTERPRISETEAM) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:ENTERPRISETEAM[key]});
        }
    }
    res.success({dataList});
} 



/**
 * 迁出去向
 * @param req 
 * @param res 
 */
function moveOutTrace(req, res) {
    let dataList = [];
    for (let key in MOVEOUTTRACE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            if (keyStr == "迁出孵化器_仍在张江" || keyStr == "迁出张江_仍在浦东" || keyStr == "迁出浦东_仍在上海") {
                keyStr = keyStr.replace("_",",");
            }
            dataList.push({key:keyStr, value:MOVEOUTTRACE[key]});
        }
    }
    res.success({dataList});
} 


/**
 * 毕业迁出原因
 */
function graduateCauseType(req, res) {
    let dataList = [];
    for (let key in MOVEOUTCAUSECLIENT) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            dataList.push({key:keyStr, value:MOVEOUTCAUSECLIENT[key]});
        }
    }
    res.success({dataList});
}


/**
 * 迁出类型
 */
function moveOutType(req, res) {
    let dataList = [];
    for (let key in MOVEOUTTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            if (keyStr == "迁出孵化器_仍在张江" || keyStr == "迁出张江_仍在浦东" || keyStr == "迁出浦东_仍在上海") {
                keyStr = keyStr.replace("_",",");
            }
            dataList.push({key:keyStr, value:MOVEOUTTYPE[key]});
        }
        
    }
    res.success({dataList});
}


/**
 * 非毕业迁出原因
 */
function moveOutCause(req, res) {
    let dataList = [];
    for (let key in MOVEOUTCAUSENOTCLIENT) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            if (keyStr == "经营成本过高_场地成本或人员成本_" || keyStr == "办公空间拓展_无合适办公空间_") {
                keyStr = keyStr.replace("_","(");
                keyStr = keyStr.replace("_",")");
            }

            dataList.push({key:keyStr, value:MOVEOUTCAUSENOTCLIENT[key]});
        }
    }
    res.success({dataList});
}


/**
 * 虚拟孵化模式
 * @param req 
 * @param res 
 */
function virtualCause(req, res) {
    let dataList = [];
    for (let key in VIRTUALCAUSE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            dataList.push({key, value:VIRTUALCAUSE[key]});
        }
    }
    res.success({dataList});
}

/**
 * 入孵状态
 */
function insidestate(req, res) {
    let dataList = [];
    for (let key in INSIDESTATE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            dataList.push({key, value:INSIDESTATE[key]});
        }
    }
    res.success({dataList});
}


/**
 * 融资轮次
 * @param req 
 * @param res 
 */
export function financingRounds(req, res) {
    let financingRoundsList = [];
    for (let key in FINANCINGROUNDS) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            financingRoundsList.push({key, value:FINANCINGROUNDS[key]});
        }
    }
    res.success({financingRoundsList});
}


/**
 * 最高学历
 * @param req 
 * @param res 
 */
export function degree(req, res) {
    let degreeList = [];
    for (let key in DEGREE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            degreeList.push({key, value:DEGREE[key]});
        }
    }
    res.success({degreeList});
}

/**
 * 获取运营模式列表
 * @param req 
 * @param res 
 */
export function operationModel(req, res) {
    let operationModelList = [];
    for (let key in OPERATIONMODEL) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            let keyStr = key;
            if (parseInt(OPERATIONMODEL[key]) == OPERATIONMODEL._投资__孵化_类型) {
                keyStr = keyStr.replace("__","+");
                keyStr = keyStr.replace("_","“");
                keyStr = keyStr.replace("_","”");
            }
            operationModelList.push({key:keyStr, value:OPERATIONMODEL[key]});
        }
    }
    res.success({operationModelList});
}

/**
 * 孵化器创业团队
 * @param req 
 * @param res 
 */
export function fuHuaQiTeam(req, res) {
    let teamList = [];
    for (let key in TEAM) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            teamList.push({key, value:TEAM[key]});
        }
    }
    res.success({teamList});
}


/**
 * 获取孵化器等级列表
 * @param req 
 * @param res 
 */
async function getFuHuaQiLv(req, res) {
    let lvList = [];
    for (let key in FUHUAQILV) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:FUHUAQILV[key]});
        }
    }
    res.success({lvList});
}


/**
 * 获取孵化器机构性质列表
 * @param req 
 * @param res 
 */
async function getInstitutionalNature(req, res) {
    let lvList = [];
    for (let key in INSTITUTIONALNATURE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:INSTITUTIONALNATURE[key]});
        }
    }
    res.success({lvList});
}

/**
 * 获取孵化器领域
 * @param req 
 * @param res 
 */
async function getFuHuaQiIndustry(req, res) {
    let lvList = [];
    for (let key in FUHUAINDUSTRY) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:FUHUAINDUSTRY[key]});
        }
    }
    res.success({lvList});
}

/**
 * 获取行业领域
 * @param req 
 * @param res 
 */
async function getIndustry(req, res) {
    let lvList = [];
    for (let key in INDUSTRY) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:INDUSTRY[key]});
        }
    }
    res.success({lvList});
}

/**
 * 获取孵化器投资方式
 * @param req 
 * @param res 
 */
 async function getFuHuaQiInvestmentStyle(req, res) {
    let lvList = [];
    for (let key in FUHUAQILNVESTMENTSTYLE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:FUHUAQILNVESTMENTSTYLE[key]});
        }
    }
    res.success({lvList});
}



async function fuhuaqiCustomTaskType(req, res) {
    let lvList = [];
    for (let key in FUHUAQICUSTOMTASKTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:FUHUAQICUSTOMTASKTYPE[key]});
        }
    }
    res.success({lvList});
}



/**
 * 企业库下拉菜单
 * @param req 
 * @param res 
 */
async function enterpriseSelectList(req, res) {
    let labelList = await selectLabelList({goal:LABELGOAL.企业, state:false});

    let dataList = [];
    dataList.push({key:"新注册企业", value:GUANWEIHUIMANANGENTERPRISELABEL.新注册企业});
    dataList.push({key:"新迁入企业", value:GUANWEIHUIMANANGENTERPRISELABEL.新迁入企业});

    labelList.forEach(info => {
        dataList.push({key:info.labelName, value:info.id});
    });

    res.success({dataList});
}

/**
 * 管理后台企业列表下拉框
 * @param req 
 * @param res 
 */
async function enterpriLabelSelectList(req, res) {
    let labelList = await selectLabelList({goal:LABELGOAL.企业, state:false});

    let dataList = [];

    labelList.forEach(info => {
        dataList.push({key:info.labelName, value:info.id});
    });

    res.success({dataList});
}


/**
 * 孵化器下拉菜单
 * @param req 
 * @param res 
 */
async function fuHuaQiSelectList(req, res) {
    let labelList = await selectLabelList({goal:LABELGOAL.孵化器, state:false, labelType:LABELTYPE.自定义标签});
    let dataList = [];

    dataList.push({key:"专业技术平台", value:FHQSYSTEMLABEL.专业技术平台});
    labelList.forEach(info => {
        dataList.push({key:info.labelName, value:info.id});
    });

    res.success({dataList});
}


/**
 * 成立支部类型
 * @param req 
 * @param res 
 */
async function fuHuaQiZhiBuTypeSelectList(req, res) {
    let lvList = [];
    for (let key in ZHIBUTYPEENUM ) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:ZHIBUTYPEENUM[key]});
        }
    }
    res.success({lvList});
}

/**
 * 未成立支部类型
 * @param req 
 * @param res 
 */
async function fuHuaQiNotZhiBuTypeSelectList(req, res) {
    let lvList = [];
    for (let key in NOTZHIBUTYPEENUM) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            lvList.push({key, value:NOTZHIBUTYPEENUM[key]});
        }
    }
    res.success({lvList});
}