package com.miaxis.app.controller.question;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.domain.entity.UserInfo;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.SecurityUtils;
import com.miaxis.question.domain.QuestionError;
import com.miaxis.question.dto.QuestionErrorDto;
import com.miaxis.question.service.IQuestionErrorService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【错题】Controller
 *
 * @author miaxis
 * @date 2021-03-16
 */
@RestController
@RequestMapping(Constants.STUDENT_PREFIX+"/question/error")
@Api(tags={"【小程序-错题】"})
public class QuestionErrorController extends BaseController{
    @Autowired
    private IQuestionErrorService questionErrorService;

    /**
     * 查询错题列表
     */
//    @PreAuthorize("@ss.hasPermi('question:error:list')")
//    @GetMapping("/list")
//    @ApiOperation("查询错题列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
//            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
//    })
//    public ResponsePageInfo<QuestionError> list(@ModelAttribute QuestionError questionError){
//        startPage();
//        UserInfo student = SecurityUtils.getLoginUser().getStudent();
//        student.getId();
//        List<QuestionError> list = questionErrorService.selectQuestionErrorList(questionError);
//        return toResponsePageInfo(list);
//    }


    @GetMapping("/getQuestionErrorList")
    @ApiOperation("查询错题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<QuestionError> getQuestionErrorList(@ModelAttribute QuestionErrorDto questionErrorDto){
        startPage();
        UserInfo student = SecurityUtils.getLoginUser().getStudent();
        questionErrorDto.setUserId(student.getId());
        List<QuestionError> list = questionErrorService.getQuestionErrorList(questionErrorDto);
        return toResponsePageInfo(list);
    }

    /**
     * 获取错题详细信息
     */
    //@PreAuthorize("@ss.hasPermi('question:error:query')")
//    @GetMapping(value = "/{id}")
//    @ApiOperation("获取错题详细信息")
//    public Response<QuestionError> getInfo(
//            @ApiParam(name = "id", value = "错题参数", required = true)
//            @PathVariable("id") Long id
//    ){
//        return Response.success(questionErrorService.getById(id));
//    }

    /**
     * 新增错题
     */
    //@PreAuthorize("@ss.hasPermi('question:error:add')")
    @Log(title = "错题", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增错题")
    public Response<Integer> add(@RequestBody QuestionError questionError){
        return toResponse(questionErrorService.save(questionError) ? 1 : 0);
    }

    /**
     * 修改错题
     */
    //@PreAuthorize("@ss.hasPermi('question:error:edit')")
//    @Log(title = "错题", businessType = BusinessTypeEnum.UPDATE)
//    @PutMapping
//    @ApiOperation("修改错题")
//    public Response<Integer> edit(@RequestBody QuestionError questionError){
//        return toResponse(questionErrorService.updateById(questionError) ? 1 : 0);
//    }

    /**
     * 删除错题
     */
    //@PreAuthorize("@ss.hasPermi('question:error:remove')")
    @Log(title = "错题", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除错题")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "错题ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(questionErrorService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
