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

import cn.hutool.core.util.StrUtil;

import com.jeesharp.business.modules.setting.application.MarketingActivityApplicationService;
import com.jeesharp.business.modules.setting.dto.MarketingActivitySaveDTO;
import com.jeesharp.business.modules.setting.entity.MarketingActivity;
import com.jeesharp.business.modules.setting.vo.MarketingActivityListVO;
import com.jeesharp.business.modules.setting.vo.MarketingActivityQueryVO;
import com.jeesharp.business.modules.setting.vo.MarketingActivityVO;
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/marketingActivity/v1")
@Tag(name = "活动营销-活动配置")
@AllArgsConstructor
public class MarketingActivityController extends BaseController {

    private final MarketingActivityApplicationService marketingActivityApplicationService;

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

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('setting:marketingActivity:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<MarketingActivityListVO>> list(@RequestBody MarketingActivityQueryVO query) {
        return AjaxResult.okData(marketingActivityApplicationService.findPage(new Page<MarketingActivity>(query), query));
    }

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

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