package com.platform.modules.live.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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 com.platform.common.annotation.SysLog;
import com.platform.common.utils.R;
import com.platform.modules.live.dto.GenerateLiveUrlDto;
import com.platform.modules.live.service.GenerateLiveUrlService;
import com.platform.plugs.live.LiveClient;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 直播流地址生成
 * @Author: yikaihong
 * @CreateDate: 2019/1/19 12:11
 * @Version: 1.0
 */
@RestController
@AllArgsConstructor
@Api(value = "直播地址管理", tags = "直播地址管理")
@Slf4j
@RequestMapping("/generate/live")
public class GenerateLiveUrlController {

    private GenerateLiveUrlService generateLiveUrlService;

    @Autowired
    private LiveClient liveClient;

    /**
     * 生成url
     *
     * @param dto
     * @return
     */
    @SysLog("生成url")
    @PostMapping(value = "/urls")
    @ApiOperation("生成url")
    public R generateLiveUrls(@Validated @RequestBody GenerateLiveUrlDto dto) {
        return generateLiveUrlService.generateLiveUrl(dto);
    }

    @SysLog("生成直播流url")
    @PostMapping(value = "/liveUrl")
    @ApiOperation("生成直播流url")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "appName", name = "appName", paramType = "form", dataType = "String"),
            @ApiImplicitParam(value = "streamName", name = "streamName", paramType = "form", dataType = "String")})
    public R generateLiveUrl(String appName, String streamName) {

        return R.ok().put("liveUrls", liveClient.liveStream().generateLiveUrl(appName, streamName, new Date())[0]);
    }

    /**
     * 消息订阅
     *
     * @return
     */
//    @SubscribeMapping("/queue/subscribeLiveUrl")
//    public R sub() {
////        System.out.println(sceneId);
//        return R.ok();
//    }


}