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

import cn.hutool.core.util.StrUtil;

import com.jeesharp.business.modules.setting.application.MarketingActivityRuleApplicationService;
import com.jeesharp.business.modules.setting.dto.MarketingActivityRuleSaveDTO;
import com.jeesharp.business.modules.setting.entity.MarketingActivityRule;
import com.jeesharp.business.modules.setting.vo.MarketingActivityRuleListVO;
import com.jeesharp.business.modules.setting.vo.MarketingActivityRuleQueryVO;
import com.jeesharp.business.modules.setting.vo.MarketingActivityRuleVO;
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 jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/setting/marketingActivityRule/v1")
@Tag(name = "活动营销-规则配置")
@AllArgsConstructor
public class MarketingActivityRuleController extends BaseController {

    private final MarketingActivityRuleApplicationService marketingActivityRuleApplicationService;

    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('setting:marketingActivityRule:info')")
    @GetMapping("info")
    public AjaxResult<MarketingActivityRuleVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(marketingActivityRuleApplicationService.get(id));
    }

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('setting:marketingActivityRule:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<MarketingActivityRuleListVO>> list(@RequestBody MarketingActivityRuleQueryVO query) {
        return AjaxResult.okData(marketingActivityRuleApplicationService.findPage(new Page<MarketingActivityRule>(query), query));
    }

    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('setting:marketingActivityRule:save')")
    @PostMapping("save")
    public AjaxResult<Void> save(@RequestBody @Valid MarketingActivityRuleSaveDTO dto) {
        marketingActivityRuleApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('setting:marketingActivityRule:delete')")
    @GetMapping("delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        marketingActivityRuleApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
