import {readFile} from "fs";

interface Word{
    bsm:string
    hz:string
    pyJs:string[]
    id:number
}
interface Ret{
    data:Word
    message:string
    haveMess:boolean
}
let words:Word[]
readFile("./word.json",'utf-8',(err, data)=>{
    if (err)console.error(err)
    words=JSON.parse(data)
})
export default defineEventHandler((event):Ret=>{
    const query = getQuery(event)
    if (query.id=="错误"){
        return {
            data:words[0],
            message:"参数错误",
            haveMess:true
        }
    }
    if (query.id>=words.length){
        return {
            data:words[0],
            message:"参数越界",
            haveMess:true
        }
    }
    return {
        data:words[query.id],
        message:"",
        haveMess:false
    }
})