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

import * as asyncHandler from 'express-async-handler';
import { FUHUAQILV, INSTITUTIONALNATURE, FUHUAINDUSTRY, INDUSTRY, FUHUAQILNVESTMENTSTYLE, OPERATIONMODEL, TEAM, DEGREE, FINANCINGROUNDS, INSIDESTATE, VIRTUALCAUSE, MOVEOUTTYPE, MOVEOUTCAUSE } from '../config/enum';

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));
}


/**
 * 迁出类型
 */
function moveOutType(req, res) {
    let dataList = [];
    for (let key in MOVEOUTTYPE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            dataList.push({key, value:MOVEOUTTYPE[key]});
        }
    }
    res.success({dataList});
}


/**
 * 迁出原因
 */
function moveOutCause(req, res) {
    let dataList = [];
    for (let key in MOVEOUTCAUSE) {
        let anyKey:any = key;
        if (isNaN(anyKey)) {
            dataList.push({key, value:MOVEOUTCAUSE[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});
}