/**
 * 机构性质 主要逻辑
 */


import * as asyncHandler from 'express-async-handler';
import * as institutionalNatureBiz from '../../biz/mobileFuHuaQi/fuHuaQi/institutionalNature';
import { checkFuHuaQiToken } from '../../middleware/user';
import { eccReqParamater } from '../../util/verificationParam';

export function setRouter(httpServer) {
    /** 任务 */
    httpServer.post('/fuhuaqi/institutionalnature/i18n/add', checkFuHuaQiToken, asyncHandler(addRegister));
    httpServer.post('/fuhuaqi/institutionalnature/i18n/update', checkFuHuaQiToken, asyncHandler(updateRegister));
    httpServer.post('/fuhuaqi/institutionalnature/i18n/info', checkFuHuaQiToken, asyncHandler(infoRegister));
    httpServer.post('/fuhuaqi/institutionalnature/i18n/list', checkFuHuaQiToken, asyncHandler(listRegister));
    httpServer.post('/fuhuaqi/institutionalnature/i18n/delete', checkFuHuaQiToken, asyncHandler(deleteRegister));
    /**创投基金 */
    httpServer.post('/fuhuaqi/institutionalnature/ptp/info', checkFuHuaQiToken, asyncHandler(PTPInfo));
    httpServer.post('/fuhuaqi/institutionalnature/ptp/update', checkFuHuaQiToken, asyncHandler(updatePTP));
    /**技术专业平台 */
    httpServer.post('/fuhuaqi/institutionalnature/professionaltechnology/info', checkFuHuaQiToken, asyncHandler(professionalTechnologyInfo));
    httpServer.post('/fuhuaqi/institutionalnature/professionaltechnology/update', checkFuHuaQiToken, asyncHandler(updateProfessionalTechnology));
}


/**
 *  创建 国际化登记
 * @param req 
 * @param res 
 */
async function addRegister(req, res) {
    let reqConf = {country:"String", partners:"String", cMode:"String", cAchievements:"String"};
    let { country, partners, cMode, cAchievements } = eccReqParamater(reqConf, req.body);
    const Uscc = req.headers.uscc;

    let result = await institutionalNatureBiz.createI18nRegister(Uscc, country, partners, cMode, cAchievements);

    res.success(result);

}

/**
 *  修改 国际化登记
 * @param req 
 * @param res 
 */
async function updateRegister(req, res) {
    let reqConf = {id:"String", country:"String", partners:"String", cMode:"String", cAchievements:"String"};
    let { country, partners, cMode, cAchievements, id } = eccReqParamater(reqConf, req.body);
    const Uscc = req.headers.uscc;

    let result = await institutionalNatureBiz.updateI18nRegister(Uscc, id, country, partners, cMode, cAchievements);

    res.success(result);

}

/**
 *  回显 国际化登记
 * @param req 
 * @param res 
 */
async function infoRegister(req, res) {
    let reqConf = {id: 'String' };//这里可以填0
    let { id } = eccReqParamater(reqConf, req.body);
    let result = await institutionalNatureBiz.selectI18nRegisterInfo(id);

    res.success(result);

}

/**
 *  查询列表 国际化登记
 * @param req 
 * @param res 
 */
async function listRegister(req, res) {
    const Uscc = req.headers.uscc;

    let result = await institutionalNatureBiz.i18nRegisterListData(Uscc);

    res.success(result);

}

/**
 *  删除 国际化登记
 * @param req 
 * @param res 
 */
async function deleteRegister(req, res) {
    let reqConf = {id: 'String' };//这里可以填0
    let { id } = eccReqParamater(reqConf, req.body);
    const Uscc = req.headers.uscc;

    let result = await institutionalNatureBiz.deleteI18nRegisterInfo(id);

    res.success(result);

}


/**
 * 回显 创投基金 
 * @param req 
 * @param res 
 */
async function PTPInfo(req, res) {
    const Uscc = req.headers.uscc;

    let result = await institutionalNatureBiz.getFuHuaQiPTP(Uscc);

    res.success(result);
}

/**
 * 修改 创投基金 
 * @param req 
 * @param res 
 */
async function updatePTP(req, res) {
    let reqConf = {isCreatePTP: 'Boolean', scalePTP:'Number', isParticipateInPTP:'Boolean' };//这里可以填0
    let { isCreatePTP, scalePTP, isParticipateInPTP } = eccReqParamater(reqConf, req.body, ["scalePTP", "isParticipateInPTP"]);
    if (isCreatePTP) eccReqParamater(reqConf, req.body, []);

    const Uscc = req.headers.uscc;
    let result = await institutionalNatureBiz.updatePTPInfo(Uscc, isCreatePTP, scalePTP, isParticipateInPTP);

    res.success(result);
}




/**
 * 回显 技术专业平台 
 * @param req 
 * @param res 
 */
async function professionalTechnologyInfo(req, res) {
    const Uscc = req.headers.uscc;

    let result = await institutionalNatureBiz.getProfessionalTechnology(Uscc);

    res.success(result);
}

/**
 * 修改 技术专业平台 
 * @param req 
 * @param res 
 */
async function updateProfessionalTechnology(req, res) {
    let reqConf = {
        isProfessionalTechnology:"Boolean", professionalTechnologyName:"String", 
        professionalTechnologyCreateTime:"Number", professionalTechnologyAmount:"Number", isCooperation:"Boolean", cooperationInstitutions:"String"
    };
    let skipList = ["professionalTechnologyName", "professionalTechnologyCreateTime", "professionalTechnologyAmount", "isCooperation", "cooperationInstitutions"];
    let { isProfessionalTechnology, professionalTechnologyName, professionalTechnologyCreateTime, professionalTechnologyAmount, isCooperation, cooperationInstitutions} = eccReqParamater(reqConf, req.body, skipList);
    if (isProfessionalTechnology) eccReqParamater(reqConf, req.body, []);

    const Uscc = req.headers.uscc;
    let result = await institutionalNatureBiz.updateProfessionalTechnology(Uscc, isProfessionalTechnology, professionalTechnologyName, professionalTechnologyCreateTime, professionalTechnologyAmount, isCooperation, cooperationInstitutions);

    res.success(result);
}

