/**
 * 知识产权主要逻辑
 * 作者:lxm
 */

import * as enterpriseData from "../../../data/enterprise/enterprise";

/**
 * 校验参数是否为空
 * @param param 参数 
 * @returns true就是空 
 */
function paramIsNull(param) {
    if (!param) return true;
    let isNull = false;
    if (typeof param == "object") {
        if (Array.isArray(param) ) isNull = param.length == 0;
        else isNull = Object.keys(param).length == 0;
    }
    else isNull = !param;

    return isNull;
}


/**
 * 修改企业知识产权信息
 * @param uscc 企业统一信用代码
 * @param alienPatent 海外专利个数
 * @param classIPatent 一类专利个数
 * @param secondClassPatent 二类专利个数
 * @returns isSuccess
 */
export async function updateIntellectualProperty(uscc:string, alienPatent:number, classIPatent:number, secondClassPatent:number) {
    let enterpriseInfo = await enterpriseData.findEnterpriseByUscc(uscc);

    enterpriseInfo.intellectualProperty = {alienPatent, classIPatent, secondClassPatent};

    if (!enterpriseInfo.tipsIntellectualProperty ) {
        enterpriseInfo.tipsIntellectualProperty = true;
    }

    await enterpriseInfo.save();

    return {isSuccess:true}
}


/**
 * 查询企业专利信息 
 * 回显
 * @param uscc 企业统一信用代码
 * @returns 
 */
export async function selectIntellectualProperty(uscc:string) {
    let enterpriseInfo = await enterpriseData.findEnterpriseByUscc(uscc);

    let intellectualProperty = {alienPatent:0, classIPatent:0, secondClassPatent:0};

    if (!paramIsNull(enterpriseInfo.intellectualProperty)) {
        intellectualProperty = enterpriseInfo.intellectualProperty;
    }

    return intellectualProperty;
}
