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.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.service.TokenService;
import com.fs.live.domain.LiveWatchConfig;
import com.fs.live.service.ILiveWatchConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播观看奖励设置Controller
 *
 * @author fs
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/live/config")
public class LiveWatchConfigController extends BaseController
{
    @Autowired
    private ILiveWatchConfigService liveWatchConfigService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询直播观看奖励设置列表
     */
//    @PreAuthorize("@ss.hasPermi('live:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveWatchConfig liveWatchConfig)
    {
        startPage();
        List<LiveWatchConfig> list = liveWatchConfigService.selectLiveWatchConfigList(liveWatchConfig);
        return getDataTable(list);
    }

    /**
     * 导出直播观看奖励设置列表
     */
//    @PreAuthorize("@ss.hasPermi('live:config:export')")
    @Log(title = "直播观看奖励设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveWatchConfig liveWatchConfig)
    {
        List<LiveWatchConfig> list = liveWatchConfigService.selectLiveWatchConfigList(liveWatchConfig);
        ExcelUtil<LiveWatchConfig> util = new ExcelUtil<LiveWatchConfig>(LiveWatchConfig.class);
        return util.exportExcel(list, "直播观看奖励设置数据");
    }

    /**
     * 获取直播观看奖励设置详细信息
     */
//    @PreAuthorize("@ss.hasPermi('live:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success("",liveWatchConfigService.selectLiveWatchConfigByLiveId(id));
    }

    /**
     * 新增直播观看奖励设置
     */
//    @PreAuthorize("@ss.hasPermi('live:config:add')")
    @Log(title = "直播观看奖励设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody String jsonConfig,@RequestParam(value = "liveId") Long liveId)
    {
        String userId = tokenService.getLoginUser(ServletUtils.getRequest()).getUser().getUserId().toString();
        return toAjax(liveWatchConfigService.insertLiveWatchConfig(userId, jsonConfig,liveId));
    }

    /**
     * 修改直播观看奖励设置
     */
//    @PreAuthorize("@ss.hasPermi('live:config:edit')")
    @Log(title = "直播观看奖励设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody String jsonConfig,@RequestParam(value = "liveId") Long liveId)
    {
        return toAjax(liveWatchConfigService.updateLiveWatchConfig(jsonConfig, liveId));
    }

    /**
     * 删除直播观看奖励设置
     */
//    @PreAuthorize("@ss.hasPermi('live:config:remove')")
    @Log(title = "直播观看奖励设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return toAjax(liveWatchConfigService.deleteLiveWatchConfigByIds(ids));
    }
}
