package com.hc.web.controller.browser.app;

import com.hc.business.model.ZccmUserVideoPosition;
import com.hc.business.service.ZccmUserVideoPositionService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户视频观看记录(UserVideoPosition)表控制层
 *
 * @author java
 * @since 2020-11-11 13:26:26
 */

@RestController
@RequestMapping("/new/api/app/userVideoPosition")
public class AppUserVideoPositionController {

    /**
     * 服务对象
     */
    private final ZccmUserVideoPositionService userVideoPositionService;

    public AppUserVideoPositionController(ZccmUserVideoPositionService userVideoPositionService) {
        this.userVideoPositionService = userVideoPositionService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 UserVideoPosition", response = Result.class)
    public Result selectAppUserVideoPosition(@PathVariable("id") Integer id) {
        return Result.success(this.userVideoPositionService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 UserVideoPosition", response = Result.class)
    public Result addAppUserVideoPosition(@Valid @RequestBody ZccmUserVideoPosition userVideoPosition) {
        return Result.success(userVideoPositionService.insert(userVideoPosition));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 UserVideoPosition", response = Result.class)
    public Result updateAppUserVideoPosition(@RequestBody ZccmUserVideoPosition userVideoPosition) {
        return Result.success(userVideoPositionService.update(userVideoPosition));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 UserVideoPosition", response = Result.class)
    public Result deleteAppUserVideoPosition(@PathVariable("id") Integer id) {
        return Result.success(userVideoPositionService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 UserVideoPosition列表(分页)", response = Result.class)
    public Result listAppUserVideoPosition(@RequestParam(defaultValue = "0") Integer page,
                                           @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(userVideoPositionService.queryAllByLimit(page, size));
    }


    @GetMapping("/{userId}/{videoId}/{courseId}/{classId}")
    @ApiOperation(value = "依据userId,vidoeId查找播放记录", response = Result.class)
    public Result findAppVideoPosition(@PathVariable("userId") Integer userId,
                                       @PathVariable("videoId") Integer videoId,
                                       @PathVariable("courseId") Integer courseId,
                                       @PathVariable("classId") Integer classId) {
        return Result.success(userVideoPositionService.findVideoPosition(userId, videoId, courseId, classId));
    }


}