package com.ruoyi.web.controller.ai;

import com.ruoyi.ai.domain.AiRechargeGift;
import com.ruoyi.ai.service.IAiRechargeGiftService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 充值赠送活动Controller
 * 
 * @author shi
 * @date 2025-11-20
 */
@RestController
@RequestMapping("/ai/gift")
public class AiRechargeGiftController extends BaseController
{
    @Autowired
    private IAiRechargeGiftService aiRechargeGiftService;

    /**
     * 查询充值赠送活动列表
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiRechargeGift aiRechargeGift)
    {
        startPage();
        List<AiRechargeGift> list = aiRechargeGiftService.selectAiRechargeGiftList(aiRechargeGift);
        return getDataTable(list);
    }

    /**
     * 导出充值赠送活动列表
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:export')")
    @Log(title = "充值赠送活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiRechargeGift aiRechargeGift)
    {
        List<AiRechargeGift> list = aiRechargeGiftService.selectAiRechargeGiftList(aiRechargeGift);
        ExcelUtil<AiRechargeGift> util = new ExcelUtil<AiRechargeGift>(AiRechargeGift.class);
        util.exportExcel(response, list, "充值赠送活动数据");
    }

    /**
     * 获取充值赠送活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        AiRechargeGift aiRechargeGift = aiRechargeGiftService.selectAiRechargeGiftById(id);
        return success(aiRechargeGift);
    }

    /**
     * 新增充值赠送活动
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:add')")
    @Log(title = "充值赠送活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AiRechargeGift aiRechargeGift)
    {
        return toAjax(aiRechargeGiftService.insertAiRechargeGift(aiRechargeGift));
    }

    /**
     * 修改充值赠送活动
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:edit')")
    @Log(title = "充值赠送活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiRechargeGift aiRechargeGift)
    {
        return toAjax(aiRechargeGiftService.updateAiRechargeGift(aiRechargeGift));
    }

    /**
     * 修改充值赠送活动
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:edit')")
    @Log(title = "充值赠送活动", businessType = BusinessType.UPDATE)
    @PutMapping("/changeUserStatus")
    public AjaxResult changeUserStatus(@RequestBody AiRechargeGift aiRechargeGift)
    {
        return toAjax(aiRechargeGiftService.changeUserStatus(aiRechargeGift));
    }

    /**
     * 删除充值赠送活动
     */
    @PreAuthorize("@ss.hasPermi('ai:rechargeGift:remove')")
    @Log(title = "充值赠送活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiRechargeGiftService.deleteAiRechargeGiftByIds(ids));
    }

    @Anonymous
    @GetMapping("/getGifStatus")
    public boolean getGifStatus() {
        return aiRechargeGiftService.isActivityAvailable(1l);
    }
}
