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

import cn.hutool.core.util.StrUtil;

import com.jeesharp.business.modules.setting.application.MarketingActivityScopeApplicationService;
import com.jeesharp.business.modules.setting.dto.MarketingActivityScopeSaveDTO;
import com.jeesharp.business.modules.setting.entity.MarketingActivityScope;
import com.jeesharp.business.modules.setting.vo.MarketingActivityScopeListVO;
import com.jeesharp.business.modules.setting.vo.MarketingActivityScopeQueryVO;
import com.jeesharp.business.modules.setting.vo.MarketingActivityScopeVO;
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/marketingActivityScope/v1")
@Tag(name = "活动营销-投放范围")
@AllArgsConstructor
public class MarketingActivityScopeController extends BaseController {

    private final MarketingActivityScopeApplicationService marketingActivityScopeApplicationService;

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

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('setting:marketingActivityScope:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<MarketingActivityScopeListVO>> list(@RequestBody MarketingActivityScopeQueryVO query) {
        return AjaxResult.okData(marketingActivityScopeApplicationService.findPage(new Page<MarketingActivityScope>(query), query));
    }

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

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