package com.xhkjedu.sstudy.controller.question;

import com.xhkjedu.sstudy.model.question.TUserBasket;
import com.xhkjedu.sstudy.service.question.UserBasketService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.sstudy.vo.question.UserBasketVo;
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 javax.annotation.Resource;
import java.util.List;

/**
* @author ywx
* @classname TUserBasketController
* @description
* @date 2020/06/09 10:33
**/
@RestController
@RequestMapping("/basket")
public class UserBasketController {
    @Resource
    private UserBasketService userBasketService;

    @PostMapping("/add")
    public ResultVo add(@RequestBody TUserBasket tUserBasket) {
        N_Utils.validation(new Object[]{tUserBasket.getUserid(),"用户id",1,tUserBasket.getQuestionid(),"试题id",2
                ,tUserBasket.getSubjectid(),"科目id",2});
        Integer id = userBasketService.save(tUserBasket);
        return new ResultVo(0, "添加成功",id);
    }

    @PostMapping("/delete_id")
    public ResultVo deleteById(@RequestBody TUserBasket tUserBasket) {
        Integer userid = tUserBasket.getUserid();
        String questionid = tUserBasket.getQuestionid();
        N_Utils.validation(new Object[]{userid,"用户id",1,questionid,"试题id",2});
        userBasketService.deleteById(userid,questionid);
        return new ResultVo(0,"移出成功");
    }

    @PostMapping("/delete_subjectid")
    public ResultVo deleteBySubjectId(@RequestBody TUserBasket tUserBasket) {
        Integer userid = tUserBasket.getUserid();
        String subjectid = tUserBasket.getSubjectid();
        N_Utils.validation(new Object[]{userid,"用户id",1,subjectid,"科目id",2});
        userBasketService.deleteBySubjectId(userid, subjectid);
        return new ResultVo(0,"清空试题篮成功");
    }

    @PostMapping("/delete_qtypeid")
    public ResultVo deleteByTypeId(@RequestBody TUserBasket tUserBasket) {
        Integer userid = tUserBasket.getUserid();
        String qtypeid = tUserBasket.getQtypeid();
        N_Utils.validation(new Object[]{userid,"用户id",1,qtypeid,"题型id",2});
        userBasketService.deleteByTypeId(userid, qtypeid);
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/detail")
    public ResultVo detail(@RequestBody TUserBasket tUserBasket) {
        Integer userid = tUserBasket.getUserid();
        String subjectid = tUserBasket.getSubjectid();
        N_Utils.validation(new Object[]{userid,"用户id",1,subjectid,"科目id",2});
        List<UserBasketVo> list = userBasketService.findAll(userid, subjectid);
        return new ResultVo(0,"获取详情成功",list);
    }
}
