// 导入BoleMbti脚本

// 引用Parse JS SDK
const Parse = require("parse/node");
Parse.initialize("dev"); // 设置applicationId
Parse.serverURL = "http://web2023.fmode.cn:9999/parse"; // 设置serverURL

let mbtiData = {
    "ISTJ": {
        "personality": "ISTJ - 守护者",
        "suitable_jobs": ["会计师", "行政助理", "工程师"]
    },
    "ISFJ": {
        "personality": "ISFJ - 慈爱者",
        "suitable_jobs": ["护士", "社会工作者", "图书管理员"]
    },
    "INFJ": {
        "personality": "INFJ - 门徒",
        "suitable_jobs": ["心理学家", "作家", "艺术家"]
    },
    "INTJ": {
        "personality": "INTJ - 学者",
        "suitable_jobs": ["科学家", "律师", "企业家"]
    },
    "ISTP": {
        "personality": "ISTP - 冒险家",
        "suitable_jobs": ["机械师", "飞行员", "摄影师"]
    },
    "ISFP": {
        "personality": "ISFP - 艺术家",
        "suitable_jobs": ["插画师", "音乐家", "花艺设计师"]
    },
    "INFP": {
        "personality": "INFP - 梦想家",
        "suitable_jobs": ["心理咨询师", "作家", "教师"]
    },
    "INTP": {
        "personality": "INTP - 学者",
        "suitable_jobs": ["程序员", "研究员", "工程师"]
    },
    "ESTP": {
        "personality": "ESTP - 实干家",
        "suitable_jobs": ["销售员", "运动员", "警察"]
    },
    "ESFP": {
        "personality": "ESFP - 表演者",
        "suitable_jobs": ["演员", "主持人", "舞蹈编导"]
    },
    "ENFP": {
        "personality": "ENFP - 公关者",
        "suitable_jobs": ["市场营销专员", "活动策划师", "公关顾问"]
    },
    "ENTP": {
        "personality": "ENTP - 挑战者",
        "suitable_jobs": ["企业顾问", "律师", "投资者"]
    },
    "ESTJ": {
        "personality": "ESTJ - 主管",
        "suitable_jobs": ["项目经理", "军官", "警察"]
    },
    "ESFJ": {
        "personality": "ESFJ - 供应者",
        "suitable_jobs": ["教育工作者", "医生", "社会工作者"]
    },
    "ENFJ": {
        "personality": "ENFJ - 慈善家",
        "suitable_jobs": ["心理咨询师", "教育家", "公益组织工作者"]
    },
    "ENTJ": {
        "personality": "ENTJ - 指挥官",
        "suitable_jobs": ["CEO", "政治家", "项目经理"]
    }
}

function importAll(){
    let MbtiList = []
    Object.keys(mbtiData).forEach(key=>{
        MbtiList.push({
            result:key,
            personality:mbtiData[key]?.personality,
            suitableJobs:mbtiData[key]?.suitable_jobs,
        })
    })

    console.log(MbtiList)
    MbtiList.forEach(async mbti => {
        // 查重
        let exists = await checkExists(mbti)
        if(exists?.id) return;
        // 新增
        let BoleMbti = Parse.Object.extend("BoleMbti");
        let bm = new BoleMbti();
        bm.set(mbti);
        bm.save();
    });
}

async function checkExists(mbti){
    let query = new Parse.Query("BoleMbti");
    query.equalTo("result",mbti?.result);
    query.equalTo("personality",mbti?.personality);
    await query.first();
    return await query.first();
}

importAll()