package com.fs.live.controller;

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.poi.ExcelUtil;
import com.fs.live.domain.LiveUserFavorite;
import com.fs.live.service.ILiveUserFavoriteService;
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 2025-07-11
 */
@RestController
@RequestMapping("/live/liveUserFavorite")
public class LiveUserFavoriteController extends BaseController
{
    @Autowired
    private ILiveUserFavoriteService liveUserFavoriteService;

    /**
     * 查询用户直播收藏列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveUserFavorite:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveUserFavorite liveUserFavorite)
    {
        startPage();
        List<LiveUserFavorite> list = liveUserFavoriteService.selectLiveUserFavoriteList(liveUserFavorite);
        return getDataTable(list);
    }

    /**
     * 导出用户直播收藏列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveUserFavorite:export')")
    @Log(title = "用户直播收藏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveUserFavorite liveUserFavorite)
    {
        List<LiveUserFavorite> list = liveUserFavoriteService.selectLiveUserFavoriteList(liveUserFavorite);
        ExcelUtil<LiveUserFavorite> util = new ExcelUtil<LiveUserFavorite>(LiveUserFavorite.class);
        return util.exportExcel(list, "用户直播收藏数据");
    }

    /**
     * 获取用户直播收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:liveUserFavorite:query')")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return AjaxResult.success(liveUserFavoriteService.selectLiveUserFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增用户直播收藏
     */
    @PreAuthorize("@ss.hasPermi('live:liveUserFavorite:add')")
    @Log(title = "用户直播收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveUserFavorite liveUserFavorite)
    {
        return toAjax(liveUserFavoriteService.insertLiveUserFavorite(liveUserFavorite));
    }

    /**
     * 修改用户直播收藏
     */
    @PreAuthorize("@ss.hasPermi('live:liveUserFavorite:edit')")
    @Log(title = "用户直播收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveUserFavorite liveUserFavorite)
    {
        return toAjax(liveUserFavoriteService.updateLiveUserFavorite(liveUserFavorite));
    }

    /**
     * 删除用户直播收藏
     */
    @PreAuthorize("@ss.hasPermi('live:liveUserFavorite:remove')")
    @Log(title = "用户直播收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(liveUserFavoriteService.deleteLiveUserFavoriteByFavoriteIds(favoriteIds));
    }
}
