package com.fs.live.controller;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.live.domain.LiveBroadcast;
import com.fs.live.service.ILiveBroadcastService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 直播列表Controller
 * 
 * @author fs
 * @date 2026-03-10
 */
@RestController
@RequestMapping("/live/broadcast")
public class LiveBroadcastController extends BaseController
{
    @Autowired
    private ILiveBroadcastService liveBroadcastService;

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

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

    /**
     * 获取直播列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:broadcast:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(liveBroadcastService.selectLiveBroadcastById(id));
    }

    /**
     * 新增直播列表
     */
    @PreAuthorize("@ss.hasPermi('live:broadcast:add')")
    @Log(title = "直播列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveBroadcast liveBroadcast)
    {
        return toAjax(liveBroadcastService.insertLiveBroadcast(liveBroadcast));
    }

    /**
     * 修改直播列表
     */
    @PreAuthorize("@ss.hasPermi('live:broadcast:edit')")
    @Log(title = "直播列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveBroadcast liveBroadcast)
    {
        return toAjax(liveBroadcastService.updateLiveBroadcast(liveBroadcast));
    }

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

    @ApiOperation("开始直播")
    @PostMapping("/startLive")
    public AjaxResult startLive()
    {
        System.out.println("调用了开始直播接口");
        return AjaxResult.success("开始直播");
    }
}
