import { ApiResponse, ApiResponseList } from "@/types";
import flyio from "../flyio";
import { DirectedSchool, Examinee, ExamPaper, ExamPaperSubmit, GetExamPaperRequestDTO, Knowledge, KnowledgeListRequestDTO, KnowledgeRecord, OpenExamineeRequestDTO, PracticeHistory, PracticeRecord, SimulatedRecord, SimulationExamSubject, SimulationTestInfo, StudyPlan, Subject, SubjectListRequestDTO, VideoStudyRecord } from "@/types/study";

/**
 * 获取学习计划
 * @param params 
 * @returns 
 */
export function getStudyPlan() {
  return flyio.get('/front/student/plan') as Promise<ApiResponse<StudyPlan>>;
}

/**
 * 保存学习计划
 * @param params 
 * @returns 
 */
export function saveStudyPlan(params: StudyPlan) {
  return flyio.post('/front/student/plan', params) as Promise<ApiResponse<any>>;
}

/**
 * 获取学习计划统计
 * @param params 
 * @returns 
 */
export function getStudyPlanStats(params: any) {
  return flyio.get('/front/student/plan/stats', params) as Promise<ApiResponse<any>>;
}


/**
 * 获取定向学校列表
 * @param params 
 * @returns 
 */
export function getDirectedSchool() {
  return flyio.get('/front/student/directed/school') as Promise<ApiResponse<DirectedSchool[]>>;
}


/**
 * 保存定向学校
 * @param params 
 * @returns 
 */
export function saveDirectedSchool(params: DirectedSchool[]) {
  return flyio.post('/front/student/directed/school', params) as Promise<ApiResponse<any>>;
}


/**
 * 获取科目列表
 * @param params 
 * @returns 
 */
export function getSubjectList(params: SubjectListRequestDTO) {
  return flyio.get('/front/paper/subject', params) as Promise<ApiResponse<Subject[]>>;
}

/**
 * 获取科目下的知识点
 * @param params 
 * @returns 
 */
export function getKnowledgeList(params: KnowledgeListRequestDTO) {
  return flyio.get('/front/paper/knowledge', params) as Promise<ApiResponse<Knowledge[]>>;
}

/**
 * 开卷
 * @param params 
 * @returns 
 */
export function getOpenExaminee(params: OpenExamineeRequestDTO) {
  return flyio.post('/front/exam/openExaminee', null, { params }, {
    headers: {
      'Content-Type': 'application/www-form-urlencoded'
    }
  }) as Promise<ApiResponse<Examinee>>;
}

/**
 * 获取试卷
 * @param params 
 * @returns 
 */
export function getPaper(params: GetExamPaperRequestDTO) {
  return flyio.get('/front/paper/paper', params) as Promise<ApiResponse<ExamPaper>>;
}

/**
 * 提交试卷
 * @param params 
 * @returns 
 */
export function commitExamineePaper(params: ExamPaperSubmit) {
  return flyio.post('/front/exam/commitExamineePaper', params) as Promise<ApiResponse<any>>;
}

/**
 * 获取试卷结果
 */
export function getExamineeResult(examineeId: number) {
  return flyio.get('/front/exam/loadExaminee', { examineeId }) as Promise<ApiResponse<Examinee>>;
}


/**
 * 获取模拟考试信息
 * @param params 
 * @returns 
 */
export function getSimulationInfo() {
  return flyio.get('/front/student/simulated/info') as Promise<ApiResponse<SimulationTestInfo>>;
}


/**
 * 收藏题目
 */
export function collectQuestion(questionId: number) {
  return flyio.post('/front/questions/collect', null, { params: { questionId } }) as Promise<ApiResponse<any>>;
}

/**
 * 取消收藏题目
 */
export function cancelCollectQuestion(questionId: number) {
  return flyio.post('/front/questions/cancelCollect', null, { params: { questionId } }) as Promise<ApiResponse<any>>;
}

/**
 * 获取知识点学习记录
 * @param params 
 * @returns 
 */
export function getKnowledgeRecord() {
  return flyio.get('/front/student/record/knowledge') as Promise<ApiResponseList<KnowledgeRecord>>;
}


/**
 * 获取模拟考试记录
 * @param params 
 * @returns 
 */
export function getSimulatedRecord() {
  return flyio.get('/front/student/record/simulated') as Promise<ApiResponse<SimulatedRecord[]>>;
}


/**
 * 获取计划学习记录
 * @param params 
 * @returns 
 */
export function getPlanStudyRecord(params: { year: number, month: number }) {
  return flyio.get('/front/student/record/planStudy', params) as Promise<ApiResponse<PracticeRecord>>;
}

/**
 * 获取视频学习记录
 * @param params 
 * @returns 
 */
export function getVideoStudyRecord() {
  return flyio.get('/front/student/record/video') as Promise<ApiResponse<VideoStudyRecord>>;
}


/**
 * 获取模拟考试科目
 * @param params 
 * @returns 
 */
export function getSimulationExamSubjects() {
  return flyio.get('/front/exam/subjects') as Promise<ApiResponse<SimulationExamSubject[]>>;
}

/**
 * 开始考试
 * @param paperId 
 * @returns 
 */
export function beginExaminee(examineeId: number) {
  return flyio.get('/front/exam/beginExaminee', { examineeId }) as Promise<ApiResponse<Examinee>>;
}


/**
 * 纠错
 * @param params 
 * @returns 
 */
export function correctQuestion(params: { questionid: number, remark: string }) {
  return flyio.post('/front/adjustWrong/correctQuestion', params) as Promise<ApiResponse<any>>;
}

/**
 * 获取计划学习记录
 * @param params 
 * @returns 
 */
export function getPracticeHistory(params: { directed: boolean }) {
  return flyio.get('/front/student/record/practice', params) as Promise<ApiResponseList<PracticeHistory>>;
}