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

import com.hc.business.model.UserVideoPosition;
import com.hc.business.service.UserVideoPositionService;
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/front/userVideoPosition")
public class FrontUserVideoPositionController {

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

    public FrontUserVideoPositionController(UserVideoPositionService userVideoPositionService) {
        this.userVideoPositionService = userVideoPositionService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 UserVideoPosition 视频播完的时候调用", response = Result.class)
    public Result addUserVideoPosition(@Valid @RequestBody UserVideoPosition userVideoPosition) {
        return Result.success(userVideoPositionService.insert(userVideoPosition));
    }

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

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

    @GetMapping("/list")
    @ApiOperation(value = "获取 UserVideoPosition列表(分页)", response = Result.class)
    public Result listUserVideoPosition(@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 findVideoPosition(@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));
    }


}