package com.ruoyi.web.controller.front;

import com.google.common.collect.Lists;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.service.WrongBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "前端V2 错题本")
@RestController
@RequestMapping("front/v2/wrongBook")
public class FrontWrongBookController extends BaseController {
    private final WrongBookService wrongBookService;

    public FrontWrongBookController(WrongBookService wrongBookService) {
        this.wrongBookService = wrongBookService;
    }

    /**
     *
     * @return
     */
    @ApiOperation("错题涉及的学科")
    @GetMapping("subjects")
    public AjaxResult subjects() {
        return AjaxResult.success(wrongBookService.findSubject());
    }

    @ApiOperation("错题列表")
    @GetMapping("wrongQuestions")
    public TableDataInfo wrongQuestions(@ApiParam("科目id") @RequestParam Long subjectId,
                                        @ApiParam(value = "页数", example = "1") @RequestParam Integer pageNum,
                                        @ApiParam(value = "页大小", example = "15") @RequestParam Integer pageSize) {
        startPage();
        return getDataTable(wrongBookService.findWrongQuestions(subjectId));
    }

    @ApiOperation("错题考卷列表")
    @GetMapping("wrongExaminees")
    public TableDataInfo wrongExaminees(@ApiParam("错题id") @RequestParam Long wrongId) {
        return getDataTable(wrongBookService.findWrongExaminees(wrongId));
    }

    @ApiOperation("删除错题")
    @PostMapping("deleteWrongQuestion")
    public AjaxResult deleteWrongQuestion(Long questionId) {
        String customerCode = String.valueOf(SecurityUtils.getLoginUser().getUserId());
        return  AjaxResult.success(wrongBookService.deleteByQuestion(customerCode, questionId));
    }
}
