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.domain.LiveQuestionBank;
import com.fs.live.service.ILiveQuestionBankService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/live/liveQuestionBank")
@AllArgsConstructor
public class LiveQuestionBankController extends BaseController {

    private final ILiveQuestionBankService liveQuestionBankService;

    /**
     * 查询题库列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestionBank:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String title) {
        startPage();
        List<LiveQuestionBank> list = liveQuestionBankService.selectLiveQuestionBankList(title);
        return getDataTable(list);
    }

    /**
     * 新增题
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestionBank:add')")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveQuestionBank liveQuestionBank) {
        return toAjax(liveQuestionBankService.insertLiveQuestionBank(liveQuestionBank, SecurityUtils.getUsername()));
    }

    /**
     * 获取题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestionBank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(liveQuestionBankService.getById(id));
    }

    /**
     * 修改题目
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestionBank:edit')")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveQuestionBank liveQuestionBank) {
        return toAjax(liveQuestionBankService.updateLiveQuestionBank(liveQuestionBank, SecurityUtils.getUsername()));
    }

    /**
     * 删除题目
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestionBank:remove')")
    @Log(title = "题库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(liveQuestionBankService.deleteLiveQuestionBankByIds(ids));
    }

}
