package com.fs.live.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.hisStore.task.LiveTask;
import com.fs.hisStore.task.MallStoreTask;
import com.fs.live.domain.Live;
import com.fs.live.service.ILiveService;
import com.fs.live.vo.LiveListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 直播Controller
 *
 * @author fs
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/live/live")
public class LiveController extends BaseController {
    @Autowired
    private ILiveService liveService;


    /**
     * 查询直播列表
     */
    @PreAuthorize("@ss.hasPermi('live:live:list')")
    @GetMapping("/list")
    public TableDataInfo list(Live live) {
        startPage();
        List<Live> list = liveService.selectLiveList(live);
        return getDataTable(list);
    }

    /**
     * 导出直播列表
     */
    @PreAuthorize("@ss.hasPermi('live:live:export')")
    @Log(title = "直播", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Live live) {
        List<Live> list = liveService.selectLiveList(live);
        ExcelUtil<Live> util = new ExcelUtil<Live>(Live.class);
        return util.exportExcel(list, "直播数据");
    }


    /**
     * 获取直播详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:live:query')")
    @GetMapping(value = "/{liveId}")
    public AjaxResult getInfo(@PathVariable("liveId") Long liveId) {
        return AjaxResult.success(liveService.selectLiveByLiveId(liveId));
    }

    /**
     * 新增直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:add')")
    @Log(title = "直播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Live live) {
        return toAjax(liveService.insertLive(live));
    }

    /**
     * 修改直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @Log(title = "直播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Live live) {
        return toAjax(liveService.updateLive(live));
    }

    /**
     * 删除直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:remove')")
    @Log(title = "直播", businessType = BusinessType.DELETE)
    @DeleteMapping("/{liveIds}")
    public AjaxResult remove(@PathVariable Long[] liveIds) {
        return toAjax(liveService.deleteLiveByLiveIds(liveIds));
    }

    @PreAuthorize("@ss.hasPermi('live:live:query')")
    @GetMapping("/living/{liveId}")
    public R getRoom(@PathVariable String liveId) {
        return liveService.getLiveRoom(liveId);
    }

    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @PostMapping("/updateLiveIsAudit")
    public Integer updateLiveIsAudit(@RequestBody Live live) {
        return liveService.updateLiveIsAudit(live);
    }



    /**
     * 批量上下架视频
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @PostMapping("/handleShelfOrUn")
    public R handleShelfOrUn(@RequestBody LiveListVo listVo) {
        return liveService.handleShelfOrUnAdmin(listVo);
    }

    /**
     * 批量删除视频
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @PostMapping("/handleDeleteSelected")
    public R handleDeleteSelected(@RequestBody LiveListVo listVo) {
        return liveService.handleDeleteSelectedAdmin(listVo);
    }
    /**
     * 校验上传的身份证信息
     */
    @PostMapping("/verifyIdInfo")
    public R verifyIdInfo(@RequestBody Map<String, String> payload) {
        return liveService.verifyIdInfo(payload);
    }

    /**
     * 结束直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @GetMapping("/finishLive")
    public R finishLive(Live live) {
        return liveService.finishLive(live);
    }
//    @GetMapping("/test/test")
//    public R test() {
//         liveTask.updateExpress();
//        return R.ok();
//    }

    /**
     * 复制直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @GetMapping("/copyLive")
    public R copyLive(Live live) {

        return liveService.copyLive(live);
    }

    /**
     * 开启直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @GetMapping("/startLive")
    public R startLive(Live live) {
        return liveService.startLive(live);
    }


}
