// 导入BoleMbti脚本

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

let music= [
    { "name": "偏爱", "image": "assets/image/BoFan.png", "author": "张芸京", "rating": 8.5 },
    { "name": "雪之华", "image": "assets/image/BoFan.png", "author": "中岛美嘉", "rating": 9.3 },
    { "name": "是你", "image": "assets/image/BoFan.png", "author": "梦然", "rating": 9.0 },
    { "name": "悬溺", "image": "assets/image/BoFan.png", "author": "葛东琪", "rating": 8.7 },
    { "name": "雾里", "image": "assets/image/BoFan.png", "author": "朵芊", "rating": 9.3 },
    { "name": "祈愿~致那个时候的你~", "image": "assets/image/BoFan.png", "author": "当山真玲", "rating": 9.1 },
    { "name": "SAKURA", "image": "assets/image/BoFan.png", "author": "Che·Nelle", "rating": 9.2 },
    { "name": "Letting Go", "image": "assets/image/BoFan.png", "author": "蔡建雅", "rating": 9.4 },
    { "name": "我们啊", "image": "assets/image/BoFan.png", "author": "三块木头", "rating": 9.5 },
    { "name": "星辰不坠落", "image": "assets/image/BoFan.png", "author": "蓝心羽", "rating": 9.6 },
    { "name": "溯", "image": "assets/image/BoFan.png", "author": "马吟吟", "rating": 9.1 },
    { "name": "你啊你啊", "image": "assets/image/BoFan.png", "author": "魏如宣", "rating": 9.0 },
    { "name": "Tattoo", "image": "assets/image/BoFan.png", "author": "GJan", "rating": 9.3 }
];

  

function importAll(){
    
    let LQLMusic= []
    Object.keys(music).forEach(key=>{
        LQLMusic.push({
            // result:key,
            name:music[key]?.name,
            author:music[key]?.author,
            rating:music[key]?.rating,
            image:music[key]?.image,
        })
    })

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

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

importAll()