package com.jeesharp.business.modules.pay.paywechatsubsidy.controller;

import com.jeesharp.business.modules.pay.paywechatsubsidy.application.PayWechatSubsidyApplicationService;
import com.jeesharp.business.modules.pay.paywechatsubsidy.dto.PayWechatSubsidyCancelDTO;
import com.jeesharp.business.modules.pay.paywechatsubsidy.dto.PayWechatSubsidyCreateDTO;
import com.jeesharp.business.modules.pay.paywechatsubsidy.dto.PayWechatSubsidyReturnDTO;
import com.jeesharp.business.modules.pay.subsidy.dto.PaySubsidyResultDTO;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信补差管理端 REST 接口，运营手动触发补差相关操作。
 *
 * @author jeesharp
 * @since 2026-06-12
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/pay/payWechatSubsidy/v1")
@Tag(name = "微信补差")
@AllArgsConstructor
public class PayWechatSubsidyController extends BaseController {

    private final PayWechatSubsidyApplicationService payWechatSubsidyApplicationService;

    @Operation(summary = "请求补差")
    @PostMapping("create")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payWechatSubsidy:create')")
    public AjaxResult<PaySubsidyResultDTO> create(@RequestBody @Valid PayWechatSubsidyCreateDTO dto) {
        return AjaxResult.okData(payWechatSubsidyApplicationService.create(dto));
    }

    @Operation(summary = "查询补差")
    @GetMapping("info")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payWechatSubsidy:info')")
    public AjaxResult<PaySubsidyResultDTO> info(
            @RequestParam("subMchId") String subMchId,
            @RequestParam("transactionId") String transactionId) {
        return AjaxResult.okData(payWechatSubsidyApplicationService.query(subMchId, transactionId));
    }

    @Operation(summary = "补差回退")
    @PostMapping("return")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payWechatSubsidy:return')")
    public AjaxResult<PaySubsidyResultDTO> returnSubsidy(@RequestBody @Valid PayWechatSubsidyReturnDTO dto) {
        return AjaxResult.okData(payWechatSubsidyApplicationService.returnSubsidy(dto));
    }

    @Operation(summary = "取消补差")
    @PostMapping("cancel")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payWechatSubsidy:cancel')")
    public AjaxResult<PaySubsidyResultDTO> cancel(@RequestBody @Valid PayWechatSubsidyCancelDTO dto) {
        return AjaxResult.okData(payWechatSubsidyApplicationService.cancel(dto));
    }
}
