package com.seer.teach.teacher.controller.app;

import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.teacher.common.req.WrongQuestionBookReq;
import com.seer.teach.teacher.common.req.WrongQuestionPageListReq;
import com.seer.teach.teacher.common.resp.SimilarQuestionResp;
import com.seer.teach.teacher.common.resp.WrongQuestionPageListResp;
import com.seer.teach.teacher.common.resp.WrongQuestionResp;
import com.seer.teach.teacher.module.entity.IdEntity;
import com.seer.teach.teacher.service.WrongQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Validated
@RestController
@EncryptionAnnotation
@DecryptionAnnotation
@RequiredArgsConstructor
@Tag(name = "APP - 错题本")
@RequestMapping("/app/wrongQuestion")
public class WrongQuestionController {

    private final WrongQuestionService wrongQuestionService;

    @PostMapping("/countBySubjectId")
    @LogPrint
    @Operation(summary = "获取各科目的错题数量")
    public ResultBean<WrongQuestionResp> getWrongQuestionBook(@RequestBody @Validated WrongQuestionBookReq params) {
        WrongQuestionResp wrongQuestion = wrongQuestionService.getWrongQuestionCount(params);
        return ResultBean.success(wrongQuestion);
    }

    @PostMapping("/list")
    @LogPrint
    @Operation(summary = "分页获取错题列表")
    public ResultBean<PageListBean<WrongQuestionPageListResp>> getWrongQuestionList(@RequestBody @Validated WrongQuestionPageListReq params) {
        PageListBean<WrongQuestionPageListResp> wrongQuestionList = wrongQuestionService.getWrongQuestionList(params);
        return ResultBean.success(wrongQuestionList);
    }

    @PostMapping("/deleteByQuestionId")
    @LogPrint
    @Operation(summary = "删除错题")
    public ResultBean deleteWrongQuestion(@RequestBody @Validated IdEntity params) {
        wrongQuestionService.deleteWrongQuestion(params);
        return ResultBean.success();
    }

    @PostMapping("/getSimilarQuestions")
    @LogPrint
    @Operation(summary = "举一反三获取相似题目")
    public ResultBean<List<SimilarQuestionResp>> getSimilarQuestions(@RequestBody @Validated IdEntity params) {
        List<SimilarQuestionResp> result = wrongQuestionService.getSimilarQuestionsByQuestionId(params.getId());
        return ResultBean.success(result);
    }


}
