package com.jeesharp.business.modules.marketing.tenantExt.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jeesharp.business.modules.marketing.tenantExt.application.MarketingTenantExtApplicationService;
import com.jeesharp.business.modules.marketing.tenantExt.dto.MarketingTenantExtSaveDTO;
import com.jeesharp.business.modules.marketing.tenantExt.vo.MarketingTenantExtInfoVO;
import com.jeesharp.framework.pojo.AjaxResult;
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.*;

/**
 * 店铺营销扩展配置 REST 接口。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/marketing/tenantExt/v1")
@Tag(name = "店铺营销配置", description = "店铺营销扩展配置")
@AllArgsConstructor
public class MarketingTenantExtController extends BaseController {

    private final MarketingTenantExtApplicationService marketingTenantExtApplicationService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "当前租户营销配置详情")
    @PreAuthorize("@ss.hasPermission('marketing:tenantExt:info')")
    @GetMapping("info")
    public AjaxResult<MarketingTenantExtInfoVO> info() {
        return AjaxResult.okData(marketingTenantExtApplicationService.getCurrent());
    }

    @ApiOperationSupport(order = 2)
    @Operation(summary = "更新营销配置")
    @PreAuthorize("@ss.hasPermission('marketing:tenantExt:update')")
    @PostMapping("update")
    public AjaxResult<Void> update(@RequestBody @Valid MarketingTenantExtSaveDTO dto) {
        marketingTenantExtApplicationService.update(dto);
        return AjaxResult.ok("保存成功");
    }
}
