package com.platform.modules.transcode.controller;

import com.platform.common.utils.R;
import com.platform.modules.transcode.service.TranscodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @author MXY
 * 2020/1/7 18:24
 */
@RestController
@RequestMapping("/transcode")
@AllArgsConstructor
@Api(value = "转码任务", tags = "转码任务")
public class TranscodeController {

    private TranscodeService transcodeService;

    @ApiIgnore
    @GetMapping("/list")
    @RequiresPermissions("live:multimedia:save")
    @ApiOperation(value = "转码任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "视频ID", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageNo", value = "页号", paramType = "query", dataType = "Integer"),
    })
    public R list(String videoId, Integer pageSize, Integer pageNo) {
        if (StringUtils.isBlank(videoId))
            return R.error("视频id不能为空");
        return transcodeService.list(videoId, pageSize, pageNo);
    }

    @GetMapping("/info")
    @RequiresPermissions("live:multimedia:save")
    @ApiOperation(value = "转码任务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "视频ID", paramType = "query", dataType = "String"),
    })
    public R info(String videoId) {
        if (StringUtils.isBlank(videoId))
            return R.error("视频id不能为空");
        return transcodeService.info(videoId);
    }

    @GetMapping("/page")
    @RequiresPermissions("live:multimedia:save")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页数", name = "page", paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "行数", name = "limit", paramType = "query", dataType = "int")
    })
    @ApiOperation(value = "转码列表")
    public R page(@ApiIgnore @RequestParam(required = false) Map<String, Object> params) {
        return R.ok().put("list", transcodeService.page(params));
    }

}
