import request from "../request";
import { AxiosPromise } from "axios";

class Test {
	/** 获取题目列表 */
	getList(params: Test.listParams): AxiosPromise<Test.listRes> {
		return request("/student/question/info/list", {
			params,
		});
	}

	/**获取免费题列表 */
	getFreeList(params: Test.listParams): AxiosPromise<Test.listRes> {
		return request("/student/question/info/selectFreeQuestionInfo", {
			params,
		});
	}

	/**获取模拟考试题列表 */
	getMockList(params: Test.listParams): AxiosPromise<Test.listRes> {
		return request("/open-api/question/info/selectTestK14QuestionInfoList", {
			params,
		});
	}

	/** 根据ids批量获取问题详情  */
	getQuestionInfoByIds(params: Test.QuestionInfoByIdsParams): AxiosPromise<Test.QuestionInfoByIdsRes> {
		return request("/student/question/info/getQuestionInfoByIds", {
			params: {
				...params,
				ids: params.ids.toString(),
			},
		});
	}
	/** 获取地方题分类 */
	selectDfQuestionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectDfQustionInfoRes[]> {
		return request({
			url: `/student/question/info/selectDfQuestionInfo`,
			params,
		});
	}

	/** 获取分类专题分类 */
	selectFlQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectFlQustionInfoRes[]> {
		return request({
			url: `/student/question/info/selectFlQuestionInfo`,
			params,
		});
	}

	/** 获取精选题分类 */
	selectJxQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectJxQustionInfoRes[]> {
		return request({
			url: `/student/question/info/selectJxQuestionInfo`,
			params,
		});
	}

	/** 获取顺序练习分类 */
	selectSxQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectSxQustionInfoRes[]> {
		return request({
			url: `/student/question/info/selectSxQuestionInfo`,
			params,
		});
	}
}

export const test = new Test();

/**
 * 获取题目分类
 */
export async function getTopicClass(path: string, params: any) {
	return request({
		url: `/student/question/info/${path}`,
		params,
	});
}

/**
 * 根据ids批量获取问题详情
 */
export const getQuestionInfoByIds = async (params: Test.QuestionInfoByIdsParams) => {
	const res = await request({
		url: "/student/question/info/getQuestionInfoByIds",
		params: {
			...params,
			ids: params.ids.toString(),
		},
	});
	return <Test.QuestionInfoByIdsRes>res.data;
};
