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

import com.jeesharp.business.modules.pay.payfundwithdraw.application.PayFundWithdrawApplicationService;
import com.jeesharp.business.modules.pay.payfundwithdraw.dto.PayFundWithdrawSubmitDTO;
import com.jeesharp.business.modules.pay.payfundwithdraw.entity.PayFundWithdraw;
import com.jeesharp.business.modules.pay.payfundwithdraw.vo.PayFundWithdrawInfoVO;
import com.jeesharp.business.modules.pay.payfundwithdraw.vo.PayFundWithdrawListVO;
import com.jeesharp.business.modules.pay.payfundwithdraw.vo.PayFundWithdrawQueryVO;
import com.jeesharp.business.modules.pay.payfundwithdraw.vo.PayFundWithdrawSubmitVO;
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.*;

/**
 * 账户资金预约提现管理端 REST 接口。
 *
 * @author jeesharp
 * @since 2026-06-12
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/pay/payFundWithdraw/v1")
@Tag(name = "账户资金提现")
@AllArgsConstructor
public class PayFundWithdrawController extends BaseController {

    private final PayFundWithdrawApplicationService payFundWithdrawApplicationService;

    @PostMapping("platform/submit")
    @Operation(summary = "平台预约提现")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:platform')")
    public AjaxResult<PayFundWithdrawSubmitVO> platformSubmit(@RequestBody @Valid PayFundWithdrawSubmitDTO dto)
            throws Exception {
        return AjaxResult.okData(payFundWithdrawApplicationService.submitPlatform(dto));
    }

    @PostMapping("platform/list")
    @Operation(summary = "平台提现记录分页")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:platform')")
    public AjaxResult<PageRespVO<PayFundWithdrawListVO>> platformList(@RequestBody PayFundWithdrawQueryVO query) {
        return AjaxResult.okData(payFundWithdrawApplicationService.findPlatformPage(new Page<>(query), query));
    }

    @GetMapping("platform/syncStatus")
    @Operation(summary = "同步平台提现状态")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:platform')")
    public AjaxResult<PayFundWithdrawInfoVO> platformSyncStatus(@RequestParam("id") String id) throws Exception {
        return AjaxResult.okData(payFundWithdrawApplicationService.syncStatus(id));
    }

    @PostMapping("merchant/submit")
    @Operation(summary = "当前租户特约商户预约提现")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:merchant')")
    public AjaxResult<PayFundWithdrawSubmitVO> merchantSubmit(@RequestBody @Valid PayFundWithdrawSubmitDTO dto)
            throws Exception {
        return AjaxResult.okData(payFundWithdrawApplicationService.submitMerchant(dto));
    }

    @PostMapping("merchant/list")
    @Operation(summary = "当前租户提现记录分页")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:merchant')")
    public AjaxResult<PageRespVO<PayFundWithdrawListVO>> merchantList(@RequestBody PayFundWithdrawQueryVO query) {
        return AjaxResult.okData(payFundWithdrawApplicationService.findMerchantPage(new Page<>(query), query));
    }

    @GetMapping("merchant/syncStatus")
    @Operation(summary = "同步商户提现状态")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:merchant')")
    public AjaxResult<PayFundWithdrawInfoVO> merchantSyncStatus(@RequestParam("id") String id) throws Exception {
        return AjaxResult.okData(payFundWithdrawApplicationService.syncStatus(id));
    }

    @GetMapping("info")
    @Operation(summary = "提现详情")
    @PreAuthorize("@ss.hasPermission('manager:business:pay:payFundWithdraw:platform') or @ss.hasPermission('manager:business:pay:payFundWithdraw:merchant')")
    public AjaxResult<PayFundWithdrawInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(payFundWithdrawApplicationService.get(id));
    }
}
