package com.fs.app.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.delivery.domain.Tag;
import com.fs.delivery.mapper.TagMapper;
import com.fs.live.domain.LiveBroadcast;
import com.fs.live.service.ILiveBroadcastService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播列表Controller
 * 
 * @author fs
 * @date 2026-03-10
 */
@Api(tags = "直播管理")
@RestController
@RequestMapping("/app/liveBroadcast")
public class LiveBroadcastController extends BaseController
{
    @Autowired
    private ILiveBroadcastService liveBroadcastService;
    @Autowired
    private TagMapper tagMapper;

    @ApiOperation("查询直播列表列表")
    @GetMapping("/list")
    public TableDataInfo list(LiveBroadcast liveBroadcast)
    {
        startPage();
        List<LiveBroadcast> list = liveBroadcastService.selectLiveBroadcastList(liveBroadcast);
        list.forEach(item -> {
            if (item.getTagIds() != null && !item.getTagIds().isEmpty()){
                List<Tag> tags = tagMapper.selectTagByIds(item.getTagIds());
                item.setTagList(tags);
            }
        });
        return getDataTable(list);
    }


    @ApiOperation("获取直播列表详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(liveBroadcastService.selectLiveBroadcastById(id));
    }

}
