package com.jeesharp.business.modules.mall.controller;

import com.jeesharp.business.modules.mall.application.MallGiftRuleApplicationService;
import com.jeesharp.business.modules.mall.dto.MallGiftRuleSaveDTO;
import com.jeesharp.business.modules.mall.vo.MallGiftRuleInfoVO;
import com.jeesharp.business.modules.mall.vo.MallGiftRuleListVO;
import com.jeesharp.business.modules.mall.vo.MallGiftRuleQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * 赠品规则管理 Controller
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/giftRule/v1")
@Tag(name = "赠品规则管理")
@AllArgsConstructor
public class MallGiftRuleController extends BaseController {

    private final MallGiftRuleApplicationService mallGiftRuleApplicationService;

    @Operation(summary = "获取详情")
    @GetMapping(value = "info")
    public AjaxResult<MallGiftRuleInfoVO> info(@RequestParam("id") String id) {
        MallGiftRuleInfoVO vo = mallGiftRuleApplicationService.get(id);
        return AjaxResult.okData(vo);
    }

    @Operation(summary = "获取列表（分页）")
    @PostMapping(value = "list")
    public AjaxResult<PageRespVO<MallGiftRuleListVO>> list(@RequestBody MallGiftRuleQueryVO query) {
        PageRespVO<MallGiftRuleListVO> page = mallGiftRuleApplicationService.findPage(new Page<>(query), query);
        return AjaxResult.okData(page);
    }

    @Operation(summary = "保存")
    @PostMapping(value = "save")
    public AjaxResult<Void> save(@RequestBody @Valid MallGiftRuleSaveDTO dto) {
        mallGiftRuleApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "删除")
    @GetMapping(value = "delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        mallGiftRuleApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
