package com.xhkjedu.slive.controller.liveplay;

import com.xhkjedu.slive.model.liveplay.LCourseSectionPlayback;
import com.xhkjedu.slive.model.liveplay.LCourseSectionPlaybackSee;
import com.xhkjedu.slive.service.liveplay.CourseSectionPlaybackService;
import com.xhkjedu.slive.vo.liveplay.CSPlaybackVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
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 javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CourseSectionPlaybackController
 * Description 课节回放
 * Author WN
 * Date 2021/6/16 10:21
 **/
@RestController
@RequestMapping("/cspb")
public class CourseSectionPlaybackController {

    @Resource
    private CourseSectionPlaybackService courseSectionPlaybackService;

    //添加回放
    @PostMapping("/add")
    public ResultVo add(@RequestBody LCourseSectionPlayback playback) {
        N_Utils.validation(new Object[]{playback.getSectionid(),"课节id",1,
        playback.getSid(),"sid",3});
        return courseSectionPlaybackService.add(playback);
    }

    //修改回放地址
    @PostMapping("/upb")
    public ResultVo updatePlayback(@RequestBody LCourseSectionPlayback playback) {
        N_Utils.validation(new Object[]{playback.getSectionid(),"课节id",1,
                playback.getSid(),"sid",3});
        return courseSectionPlaybackService.updatePlayback(playback);
    }

    //课节所有回放
    @PostMapping("/pbs")
    public ResultVo listPlaybacksBySectionid(@RequestBody LCourseSectionPlayback playback) {
        N_Utils.validation(new Object[]{playback.getSectionid(),"课节id",1});
        List<Map> list = courseSectionPlaybackService.listSectionPlaybacks(playback.getSectionid());
        return new ResultVo(0,"成获取课节下直播回放",list);
    }

    //修改视频回放观看次数
    @PostMapping("/see")
    public ResultVo updateReadnum(@RequestBody LCourseSectionPlaybackSee playbackSee) {
        N_Utils.validation(new Object[]{playbackSee.getPbid(),"直播回放id",1});
        return courseSectionPlaybackService.updateReadnum(playbackSee);
    }

    //修改视频回放下载次数
    @PostMapping("/dn")
    public ResultVo updateDownnum(@RequestBody LCourseSectionPlayback playback) {
        N_Utils.validation(new Object[]{playback.getPbid(),"直播回放id",1});
        courseSectionPlaybackService.updateDownnum(playback);
        return new ResultVo(0,"成功更新视频下载次数");
    }

    /**
     * @Description 根据课节名称删除回放地址
     * @Date 2023/11/20 11:05
     * @Author YWX
     * @Param [pb]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/del_pb")
    public ResultVo deletePb(@RequestBody CSPlaybackVo pb) {
        if (!N_Utils.isTrueInteger(pb.getBatchnum())) return new ResultVo(1, "批处理数量不能为空");
        List<String> sectionnames = pb.getSectionnames();
        if (N_Utils.isListEmpty(sectionnames)) return new ResultVo(1, "课节名称不能为空");
        for (String sectionname : sectionnames) {
            if (N_Utils.isEmpty(sectionname)) return new ResultVo(1, "课节名称不能为空");
        }
        courseSectionPlaybackService.deletePb(pb);
        return new ResultVo(0, "删除回放成功");
    }


}
