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.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.SecurityUtils;
import com.fs.live.domain.LiveRedConf;
import com.fs.live.service.ILiveRedConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播红包记录配置Controller
 *
 * @author fs
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/live/liveRedConf")
public class LiveRedConfController extends BaseController
{
    @Autowired
    private ILiveRedConfService liveRedConfService;

    /**
     * 查询直播红包记录配置列表
     */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveRedConf liveRedConf)
    {
        startPage();
        List<LiveRedConf> list = liveRedConfService.selectLiveRedConfList(liveRedConf);
        return getDataTable(list);
    }

    @GetMapping("/listOn")
    public TableDataInfo listOn(LiveRedConf liveRedConf)
    {
        startPage();
        List<LiveRedConf> list = liveRedConfService.selectLiveRedConfListOn(liveRedConf);
        return getDataTable(list);
    }

    /**
     * 导出直播红包记录配置列表
     */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:export')")
    @Log(title = "直播红包记录配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveRedConf liveRedConf)
    {
        List<LiveRedConf> list = liveRedConfService.selectLiveRedConfList(liveRedConf);
        ExcelUtil<LiveRedConf> util = new ExcelUtil<LiveRedConf>(LiveRedConf.class);
        return util.exportExcel(list, "直播红包记录配置数据");
    }

    /**
     * 获取直播红包记录配置详细信息
     */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:query')")
    @GetMapping(value = "/{redId}")
    public AjaxResult getInfo(@PathVariable("redId") Long redId)
    {
        return AjaxResult.success(liveRedConfService.selectLiveRedConfByRedId(redId));
    }

    /**
     * 新增直播红包记录配置
     */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:add')")
    @Log(title = "直播红包记录配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveRedConf liveRedConf)
    {
        return toAjax(liveRedConfService.insertLiveRedConf(liveRedConf));
    }

    /**
     * 修改直播红包记录配置
     */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:edit')")
    @Log(title = "直播红包记录配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody LiveRedConf liveRedConf)
    {
        liveRedConfService.updateLiveRedConf(liveRedConf);
        return R.ok(liveRedConf.getRedStatus().toString());
    }

    /**
     * 删除直播红包记录配置
     */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:remove')")
    @Log(title = "直播红包记录配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{redIds}")
    public AjaxResult remove(@PathVariable Long[] redIds)
    {
        return toAjax(liveRedConfService.deleteLiveRedConfByRedIds(redIds));
    }

//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:query')")
    @GetMapping("/live/{liveId}")
    public List<LiveRedConf> getByLiveId(@PathVariable Long liveId) {
        return liveRedConfService.getByLiveId(liveId);
    }

    /**
     * 点击发放红包
     * */
//    @PreAuthorize("@ss.hasPermi('live:liveRedConf:edit')")
    @PostMapping("/start/{redId}")
    public String start(@PathVariable String redId) {
        return liveRedConfService.start(redId, SecurityUtils.getLoginUser().getUser().getUserId());
    }



}
