package cn.iocoder.yudao.module.shop.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.shop.entity.ShopCouponTemplate;
import cn.iocoder.yudao.module.shop.service.IShopCouponTemplateService;
import cn.iocoder.yudao.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券模板Controller
 *
 * @author ruoyi
 * @date 2023-08-29
 */
@RestController
@RequestMapping("/admin-api/shop/couponTemplate")
public class ShopCouponTemplateController extends BaseController
{
    @Autowired
    private IShopCouponTemplateService shopCouponTemplateService;

    /**
     * 查询优惠券模板列表
     */
//    @PreAuthorize("@ss.hasPermi('shop:couponTemplate:list')")
    @GetMapping("/list")
    public CommonResult list(ShopCouponTemplate shopCouponTemplate,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<ShopCouponTemplate> page = new Page<>(pageNum, pageSize);
        IPage<ShopCouponTemplate> list = shopCouponTemplateService.selectShopCouponTemplateList(page,shopCouponTemplate);
        return success(list);
    }

    /**
     * 导出优惠券模板列表
     */
//    @PreAuthorize("@ss.hasPermi('shop:couponTemplate:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopCouponTemplate shopCouponTemplate,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<ShopCouponTemplate> page = new Page<>(pageNum, pageSize);
        IPage<ShopCouponTemplate> list = shopCouponTemplateService.selectShopCouponTemplateList(page,shopCouponTemplate);
        ExcelUtil<ShopCouponTemplate> util = new ExcelUtil<ShopCouponTemplate>(ShopCouponTemplate.class);
        util.exportExcel(response, list.getRecords(), "优惠券模板数据");
    }

    /**
     * 获取优惠券模板详细信息
     */
//    @PreAuthorize("@ss.hasPermi('shop:couponTemplate:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopCouponTemplateService.selectShopCouponTemplateById(id));
    }

    /**
     * 新增优惠券模板
     */
//    @PreAuthorize("@ss.hasPermi('shop:couponTemplate:add')")
    @PostMapping
    public CommonResult add(@RequestBody ShopCouponTemplate shopCouponTemplate)
    {
        return toAjax(shopCouponTemplateService.insertShopCouponTemplate(shopCouponTemplate));
    }

    /**
     * 修改优惠券模板
     */
//    @PreAuthorize("@ss.hasPermi('shop:couponTemplate:edit')")
    @PutMapping
    public CommonResult edit(@RequestBody ShopCouponTemplate shopCouponTemplate)
    {
        return toAjax(shopCouponTemplateService.updateShopCouponTemplate(shopCouponTemplate));
    }

    /**
     * 删除优惠券模板
     */
//    @PreAuthorize("@ss.hasPermi('shop:couponTemplate:remove')")
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopCouponTemplateService.deleteShopCouponTemplateByIds(ids));
    }
}
