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.poi.ExcelUtil;
import com.fs.live.domain.LiveCart;
import com.fs.live.service.ILiveCartService;
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-08
 */
@RestController
@RequestMapping("/live/liveCart")
public class LiveCartController extends BaseController
{
    @Autowired
    private ILiveCartService liveCartService;

    /**
     * 查询购物车列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveCart:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveCart liveCart)
    {
        startPage();
        List<LiveCart> list = liveCartService.selectLiveCartList(liveCart);
        return getDataTable(list);
    }

    /**
     * 导出购物车列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveCart:export')")
    @Log(title = "购物车", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveCart liveCart)
    {
        List<LiveCart> list = liveCartService.selectLiveCartList(liveCart);
        ExcelUtil<LiveCart> util = new ExcelUtil<LiveCart>(LiveCart.class);
        return util.exportExcel(list, "购物车数据");
    }

    /**
     * 获取购物车详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:liveCart:query')")
    @GetMapping(value = "/{cardId}")
    public AjaxResult getInfo(@PathVariable("cardId") Long cardId)
    {
        return AjaxResult.success(liveCartService.selectLiveCartByCartId(cardId));
    }

    /**
     * 新增购物车
     */
    @PreAuthorize("@ss.hasPermi('live:liveCart:add')")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveCart liveCart)
    {
        return toAjax(liveCartService.insertLiveCart(liveCart));
    }

    /**
     * 修改购物车
     */
    @PreAuthorize("@ss.hasPermi('live:liveCart:edit')")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveCart liveCart)
    {
        return toAjax(liveCartService.updateLiveCart(liveCart));
    }

    /**
     * 删除购物车
     */
    @PreAuthorize("@ss.hasPermi('live:liveCart:remove')")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cardIds}")
    public AjaxResult remove(@PathVariable Long[] cardIds)
    {
        return toAjax(liveCartService.deleteLiveCartByCartIds(cardIds));
    }
}
