package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.LifeUserLearningRecord;
import shop.alien.entity.store.vo.LifeUserLearningVideoVo;
import shop.alien.store.service.LifeUserLearningRecordService;

import java.util.List;

@Api(tags = {"用户学习记录"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/lifeUserLearningRecord")
@RequiredArgsConstructor
public class LifeUserLearningRecordController {

    private final LifeUserLearningRecordService lifeUserLearningRecordService;

    @ApiOperation("新增用户学习记录")
    @ApiOperationSupport(order = 1)
    @PostMapping("/add")
    public R<String> add(@RequestBody LifeUserLearningRecord lifeUserLearningRecord) {
        return lifeUserLearningRecordService.add(lifeUserLearningRecord);
    }

    @ApiOperation("根据ID删除用户学习记录")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/deleteById")
    public R<String> deleteById(@RequestParam Integer id) {
        return lifeUserLearningRecordService.deleteById(id);
    }

    @ApiOperation("更新用户学习记录")
    @ApiOperationSupport(order = 3)
    @PostMapping("/update")
    public R<String> update(@RequestBody LifeUserLearningRecord lifeUserLearningRecord) {
        return lifeUserLearningRecordService.update(lifeUserLearningRecord);
    }

    @ApiOperation("根据ID查询用户学习记录")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getById")
    public R<LifeUserLearningRecord> getById(@RequestParam Integer id) {
        return lifeUserLearningRecordService.getInfoById(id);
    }

    @ApiOperation("根据用户ID查询用户学习记录")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getByUserId")
    public R<LifeUserLearningRecord> getByUserId(@RequestParam Integer userId) {
        return lifeUserLearningRecordService.getByUserId(userId);
    }

    @ApiOperation("分页查询用户学习记录列表")
    @ApiOperationSupport(order = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/list")
    public R<IPage<LifeUserLearningRecord>> list(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestParam(required = false) Integer userId) {
        return lifeUserLearningRecordService.list(pageNum, pageSize, userId);
    }

    @ApiOperation("获取视频学习列表")
    @ApiOperationSupport(order = 7)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getListByUserId")
    public R<List<LifeUserLearningVideoVo>> getListByUserId(@RequestParam Integer userId) {
        return lifeUserLearningRecordService.getListByUserId(userId);
    }
}

