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

import cn.hutool.core.util.StrUtil;

import com.jeesharp.business.modules.setting.application.MarketingPosterTemplateApplicationService;
import com.jeesharp.business.modules.setting.dto.MarketingPosterTemplateSaveDTO;
import com.jeesharp.business.modules.setting.entity.MarketingPosterTemplate;
import com.jeesharp.business.modules.setting.vo.MarketingPosterTemplateListVO;
import com.jeesharp.business.modules.setting.vo.MarketingPosterTemplateQueryVO;
import com.jeesharp.business.modules.setting.vo.MarketingPosterTemplateVO;
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/marketingPosterTemplate/v1")
@Tag(name = "活动营销-海报模板")
@AllArgsConstructor
public class MarketingPosterTemplateController extends BaseController {

    private final MarketingPosterTemplateApplicationService marketingPosterTemplateApplicationService;

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

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('setting:marketingPosterTemplate:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<MarketingPosterTemplateListVO>> list(@RequestBody MarketingPosterTemplateQueryVO query) {
        return AjaxResult.okData(marketingPosterTemplateApplicationService.findPage(new Page<MarketingPosterTemplate>(query), query));
    }

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

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