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

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.zhangmeng.online.exam.ui.api.ApiUtils;
import com.zhangmeng.online.exam.ui.module.QuestionType;
import com.zhangmeng.online.exam.ui.module.SubjectType;
import com.zhangmeng.online.exam.ui.utils.HttpUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zm
 * @date 2025/4/1 14:37
 * @version: 1.0
 */
public class SubjectService {

    public static List<SubjectType> getALLSubjectType() {
        Map<String, Object> params = new HashMap<>();
        params.put("token", UserService.getCurrentUser().getToken());
//        params.put("token", HttpUtils.Token);
        String response = HttpUtils.GET(ApiUtils.API_URL + "/subject/getALLSubjectType", params);
        JSONObject jsonObject = JSONObject.parseObject(response);
        List<SubjectType> questionTypes = new ArrayList<>();
        if (jsonObject.getIntValue("code") == 200) {
            questionTypes = JSONArray.parseArray(jsonObject.getString("data"), SubjectType.class);
        }
        return questionTypes;
    }
}
