/**
 *  孵化器  创投基金 和 专业技术平台 逻辑
 * 作者：lxm
 */

import * as i18nRegisterData from "../../../../data/fuHuaQi/instituQualify/i18nRegister";
import * as icrData from "../../../../data/fuHuaQi/instituQualify/icr";
import * as startupTeacherData from "../../../../data/fuHuaQi/instituQualify/startupTeacher";
import * as zjBeyondLayoutData from "../../../../data/fuHuaQi/instituQualify/zjBeyondLayout";
import {  STATEENUM } from "../../../../config/enum";
import * as fuhuaqiData from "../../../../data/fuHuaQi/fuhuaqi";
import { addFuHuaQiPoint } from "../../../point";
import * as pointConfig from "../../../../config/pointConfig";
import { fuHuaQiEventLabel, inOnceLabelToFuHuaQi, outLabelToFuHuaQi } from "../../../label";
import { FHQSYSTEMLABEL } from "../../../../config/enum/labelEnum";


/**
 * 修改创投基金登记信息
 * @param uscc 孵化器统一信用代码
 * @param isCreatePTP  是否成立创投基金
 * @param scalePTP 基金规模
 * @param isParticipateInPTP 是否参与创投基金
 * @param participatingFundCompany 参股基金公司名
 * @returns isSuccess 是否操作成功
 */
export async function updatePTPInfo(uscc:string, isCreatePTP:number, scalePTP:number, isParticipateInPTP:boolean, participatingFundCompany:string) {
    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);


    let oldData = {
        isCreatePTP:fuHuaQiInfo.isCreatePTP,
        scalePTP:fuHuaQiInfo.scalePTP,
        isParticipateInPTP:fuHuaQiInfo.isParticipateInPTP,
        participatingFundCompany:fuHuaQiInfo.participatingFundCompany, 
    };
    let newData = { isCreatePTP, scalePTP, isParticipateInPTP, participatingFundCompany };

    addFuHuaQiPoint( uscc, pointConfig.FUHUAQINODEENUM.机构资质_创投基金登记, oldData, newData, pointConfig.OPERATETYPEENUM.修改 );

    fuHuaQiInfo.isCreatePTP = isCreatePTP;
    fuHuaQiInfo.scalePTP = scalePTP;
    fuHuaQiInfo.isParticipateInPTP = isParticipateInPTP;
    fuHuaQiInfo.participatingFundCompany = participatingFundCompany,

    await fuHuaQiInfo.save();

   

    return {isSuccess:true};
}


/**
 * 回显 创投基金登记信息
 * @param uscc 孵化器统一信用代码
 * @returns 
 */
export async function getFuHuaQiPTP(uscc:string) {
    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

    let PTPInfo = {
        isCreatePTP:fuHuaQiInfo.isCreatePTP,
        scalePTP:fuHuaQiInfo.scalePTP,
        isParticipateInPTP:fuHuaQiInfo.isParticipateInPTP,
        participatingFundCompany:fuHuaQiInfo.participatingFundCompany,
    };

    return {PTPInfo};
}


/**
 * 修改 专业技术平台信息 
 * @param uscc 孵化器统一信用代码
 * @param isProfessionalTechnology 是否专业技术平台 
 * @param professionalTechnologyName 专业技术平台名称 
 * @param professionalTechnologyCreateTime 时间 
 * @param professionalTechnologyAmount 投资金额万元 
 * @param isCooperation 是否与第三方合作 
 * @param cooperationInstitutions 合作机构名称 
 * @returns 
 */
export async function updateProfessionalTechnology(uscc:string, isProfessionalTechnology:number, professionalTechnologyName:String, 
    professionalTechnologyCreateTime:number, professionalTechnologyAmount:number, isCooperation:boolean, cooperationInstitutions:string) {

    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

    let oldData = {
        isProfessionalTechnology:fuHuaQiInfo.isProfessionalTechnology,
        professionalTechnologyName:fuHuaQiInfo.professionalTechnologyName,
        professionalTechnologyCreateTime:fuHuaQiInfo.professionalTechnologyCreateTime,
        professionalTechnologyAmount:fuHuaQiInfo.professionalTechnologyAmount,
        isCooperation:fuHuaQiInfo.isCooperation,
        cooperationInstitutions:fuHuaQiInfo.cooperationInstitutions,
    };
    let newData = {
        isProfessionalTechnology,
        professionalTechnologyName,
        professionalTechnologyCreateTime,
        professionalTechnologyAmount,
        isCooperation,
        cooperationInstitutions,
    };

    addFuHuaQiPoint( uscc, pointConfig.FUHUAQINODEENUM.机构资质_专业技术平台登记, oldData, newData, pointConfig.OPERATETYPEENUM.修改 );

    fuHuaQiInfo.isProfessionalTechnology= isProfessionalTechnology;//是否专业技术平台
    fuHuaQiInfo.professionalTechnologyName= professionalTechnologyName;//专业技术平台名称
    fuHuaQiInfo.professionalTechnologyCreateTime= professionalTechnologyCreateTime;//时间  年份 xxxx年01月01日 的时间戳
    fuHuaQiInfo.professionalTechnologyAmount= professionalTechnologyAmount;//投资金额万元
    fuHuaQiInfo.isCooperation= isCooperation;//是否与第三方合作
    fuHuaQiInfo.cooperationInstitutions= cooperationInstitutions;//合作机构名称

    //标签
    fuHuaQiEventLabel(fuHuaQiInfo, FHQSYSTEMLABEL.专业技术平台, professionalTechnologyName);


    await fuHuaQiInfo.save();

    return {isSuccess:true};
}


/**
 * 回显 专业技术平台信息 
 * @param uscc 孵化器统一信用代码
 * @returns 
 */
export async function getProfessionalTechnology(uscc:string) {
    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

    let professionalTechnologyInfo = {
        isProfessionalTechnology:fuHuaQiInfo.isProfessionalTechnology,
        professionalTechnologyName:fuHuaQiInfo.professionalTechnologyName,
        professionalTechnologyCreateTime:fuHuaQiInfo.professionalTechnologyCreateTime,
        professionalTechnologyAmount:fuHuaQiInfo.professionalTechnologyAmount,
        isCooperation:fuHuaQiInfo.isCooperation,
        cooperationInstitutions:fuHuaQiInfo.cooperationInstitutions,
    };

    return { professionalTechnologyInfo };
}


/**
 * 机构资质概览
 * @param uscc 孵化器统一信用代码
 * @returns 
 */
export async function overview(uscc:string) {
    let i18n = await i18nRegisterData.getI18nRegisterCountByParam({uscc});
    let icr = await icrData.getIcrCountByParam({uscc});
    let startupteacher = await startupTeacherData.getStartupTeacherCountByParam({uscc});
    let zjbeyondlayout = await zjBeyondLayoutData.getZjBeyondLayoutCountByParam({uscc});
    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);
    let data = {
        i18n,
        icr,
        startupteacher,
        zjbeyondlayout,
        isCreatePTP:fuHuaQiInfo.isCreatePTP == STATEENUM.是 || fuHuaQiInfo.isCreatePTP == STATEENUM.否,
        isProfessionalTechnology:fuHuaQiInfo.isProfessionalTechnology == STATEENUM.是 || fuHuaQiInfo.isProfessionalTechnology == STATEENUM.否
    };

    return data;
}

