package com.fs.company.controller.live;

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.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.framework.security.SecurityUtils;
import com.fs.live.service.ILiveQuestionLiveService;
import com.fs.live.vo.LiveQuestionLiveVO;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/live/liveQuestionLive")
@AllArgsConstructor
public class LiveQuestionLiveController extends BaseController {

    private final ILiveQuestionLiveService liveQuestionLiveService;

    /**
     * 查询直播间题库列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Long liveId) {
        startPage();
        List<LiveQuestionLiveVO> list = liveQuestionLiveService.selectLiveQuestionLiveList(liveId);
        return getDataTable(list);
    }

    /**
     * 查询直播间题库列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveConfig:list')")
    @GetMapping("/optionList")
    public TableDataInfo optionList(@RequestParam Long liveId, @RequestParam(required = false) String title) {
        startPage();
        List<LiveQuestionLiveVO> list = liveQuestionLiveService.selectLiveQuestionOptionList(liveId, title);
        return getDataTable(list);
    }

    /**
     * 新增题
     */
    @PreAuthorize("@ss.hasPermi('live:liveConfig:list')")
    @Log(title = "直播间题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam Long liveId, @RequestParam List<Long> questionIds) {
        return toAjax(liveQuestionLiveService.insertLiveQuestion(liveId, questionIds, SecurityUtils.getUsername()));
    }

    /**
     * 删除题目
     */
    @PreAuthorize("@ss.hasPermi('live:liveConfig:list')")
    @Log(title = "直播间题库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{liveId}")
    public AjaxResult remove(@PathVariable Long liveId, @RequestParam List<Long> ids) {
        return toAjax(liveQuestionLiveService.deleteLiveQuestionByIds(liveId, ids));
    }
}
