package com.zhangmeng.online.exam.ui.service;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.zhangmeng.online.exam.ui.module.QuestionOption;
import com.zhangmeng.online.exam.ui.module.Subject;
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
import com.zhangmeng.online.exam.ui.utils.ApiUtils;
import com.zhangmeng.online.exam.ui.utils.FxUtils;
import com.zhangmeng.online.exam.ui.utils.HttpUtils;

import java.util.HashMap;
import java.util.Map;

import static com.zhangmeng.online.exam.ui.utils.FxUtils.Permission_DynamicTableComponent;

/**
 * @author zm
 * @date 2025/4/11 12:20
 * @version: 1.0
 */
public class OptionService {

    public static boolean saveOption(Map<String, Object> option) {
        String result = HttpUtils.POST(ApiUtils.API_URL + "/option/save", option);
        JSONObject jsonObject = JSON.parseObject(result);
        return jsonObject.getIntValue("code") == 200;
    }

    public static QuestionOption getQuestionOptionById(String id) {
        QuestionOption questionOption = null  ;
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        String result = HttpUtils.GET(ApiUtils.API_URL + "/option/getQuestionOptionById",params);
        JSONObject jsonObject = JSON.parseObject(result);
        if (jsonObject.getIntValue("code") == 200) {
            questionOption = new QuestionOption();
            JSONObject data = jsonObject.getJSONObject("data");
            questionOption.setId(data.getString("id"));
            questionOption.setName(data.getString("name"));
            questionOption.setOptionContent(data.getString("optionContent"));
            questionOption.setExplanation(data.getString("explanation"));
            questionOption.setAnswer(data.getBoolean("isAnswer"));
        }
        return questionOption;
    }
}
