
/**  
 * 孵化器 机构资质
 *  
 */

import * as fuhuaqiData from "../../../data/fuHuaQi/fuhuaqi";
import { getI18nRegisterId } from "../../../tools/system";
import { addRegister, deleteI18nRegisterListById, findI18nRegisterListByParam, findOneI18nRegister } from "../../../data/fuHuaQi/i18nRegister";


/**
 * 创建国际化登记
 * @param uscc 企业统一信用代码
 * @param country 国家
 * @param partners 合作机构
 * @param cMode 合作方式
 * @param cAchievements 合作成果
 * @returns 
 */
export async function createI18nRegister(uscc:string, country:string, partners:string, cMode:string, cAchievements:string) {

    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

    let id = getI18nRegisterId(uscc);
    await addRegister(id, uscc, fuHuaQiInfo.name, country, partners, cMode, cAchievements);
    
    return {isSuccess:true};
}


/**
 * 修改国际化登记
 * @param uscc 企业统一信用代码
 * @param id 标识
 * @param country 国家
 * @param partners 合作机构
 * @param cMode 合作方式
 * @param cAchievements 合作成果
 * @returns 
 */
export async function updateI18nRegister(uscc:string, id:string, country:string, partners:string, cMode:string, cAchievements:string) {
    let registerInfo = await findOneI18nRegister(id);

    registerInfo.country = country;
    registerInfo.partners = partners;
    registerInfo.cMode = cMode;
    registerInfo.cAchievements = cAchievements;

    await registerInfo.save();

    return {isSuccess:true};
}


export async function selectI18nRegisterInfo(id:string) {
    let registerInfo = await findOneI18nRegister(id);

    let registerData = {
        country : registerInfo.country,
        partners : registerInfo.partners,
        cMode : registerInfo.cMode,
        cAchievements : registerInfo.cAchievements,
    };

    return {registerData} 
}

export async function deleteI18nRegisterInfo(id:string) {
    await deleteI18nRegisterListById(id);

    return {isSuccess:true} 
}

export async function i18nRegisterListData(uscc) {
    let registerList = await findI18nRegisterListByParam({uscc});

    let dataList = [];
    registerList.forEach(info => {
        dataList.push({
            id:info.id,
            country:info.country,
            partners:info.partners,
            cMode:info.cMode,
            cAchievements:info.cAchievements,
        });
    });

    return {dataList}
}


/**
 * 修改创投基金登记信息
 * @param uscc 
 * @param isCreatePTP 
 * @param scalePTP 
 * @param isParticipateInPTP 
 */
export async function updatePTPInfo(uscc:string, isCreatePTP:boolean, scalePTP:number, isParticipateInPTP:boolean) {
    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

    fuHuaQiInfo.isCreatePTP = isCreatePTP;
    fuHuaQiInfo.scalePTP = scalePTP;
    fuHuaQiInfo.isParticipateInPTP = isParticipateInPTP;

    await fuHuaQiInfo.save();

    return {isSuccess:true};
}


export async function getFuHuaQiPTP(uscc:string) {
    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

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

    return {PTPInfo};
}


export async function updateProfessionalTechnology(uscc:string, isProfessionalTechnology:boolean, professionalTechnologyName:String, 
    professionalTechnologyCreateTime:number, professionalTechnologyAmount:number, isCooperation:boolean, cooperationInstitutions:string) {

    let fuHuaQiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);

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

    await fuHuaQiInfo.save();

    return {isSuccess:true};
}


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