package com.seer.teach.pay.admin.withdrawal.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.pay.admin.withdrawal.controller.request.PayWithdrawalApplyPageRequest;
import com.seer.teach.pay.admin.withdrawal.controller.request.PayWithdrawalApplyReq;
import com.seer.teach.pay.admin.withdrawal.controller.request.PayWithdrawalAuditReq;
import com.seer.teach.pay.admin.withdrawal.controller.response.PayWithdrawalApplyResponse;
import com.seer.teach.pay.admin.withdrawal.service.AdminPayWithdrawalApplyQueryService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 申请提现控制器
 *
 * @author ZS
 * @since 2025-09-17
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/withdrawal/apply")
@Tag(name = "管理端 - 提现申请管理")
public class AdminPayMerchantWithdrawalApplyController {

    private final AdminPayWithdrawalApplyQueryService payWithdrawalApplyService;

    @PostMapping("/paged")
    @Operation(summary = "分页查询提现申请")
    @SaCheckPermission("admin:pay:withdrawal:apply:page")
    public ResultBean<PageListBean<PayWithdrawalApplyResponse>> pageList(@Parameter(description = "分页查询参数") @RequestBody PayWithdrawalApplyPageRequest pageRequest) {
        return ResultBean.success(payWithdrawalApplyService.pageList(pageRequest));
    }

    @PostMapping("/list")
    @Operation(summary = "获取PayWithdrawalApply列表")
    @SaCheckPermission("admin:pay:withdrawal:apply:list")
    public ResultBean<List<PayWithdrawalApplyResponse>> list(@Parameter(description = "查询参数") @RequestBody PayWithdrawalApplyPageRequest queryParam) {
        return ResultBean.success(payWithdrawalApplyService.list(queryParam));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取提现申请")
    @SaCheckPermission("admin:pay:withdrawal:apply:detail")
    public ResultBean<PayWithdrawalApplyResponse> getDetail(@Parameter(description = "ID") @PathVariable Long id) {
        return ResultBean.success(payWithdrawalApplyService.getDetail(id));
    }

    @PostMapping("/audit/{id}")
    @Operation(summary = "审核提现申请")
    @SaCheckPermission("admin:pay:withdrawal:apply:audit")
    public ResultBean<Boolean> auditWithdrawal(@Parameter(description = "ID") @PathVariable Integer id,
                                               @Parameter(description = "审核参数") @RequestBody PayWithdrawalAuditReq auditRequest) {
        return ResultBean.success(payWithdrawalApplyService.auditWithdrawal(id, auditRequest));
    }

    @PutMapping
    @Operation(summary = "更新提现申请")
    @SaCheckPermission("admin:pay:withdrawal:apply:update")
    public ResultBean<Boolean> update(@Parameter(description = "更新参数") @RequestBody PayWithdrawalApplyReq payWithdrawalApply) {
        return ResultBean.success(payWithdrawalApplyService.updateById(payWithdrawalApply));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除提现申请")
    @SaCheckPermission("admin:pay:withdrawal:apply:delete")
    public ResultBean<Boolean> delete(@Parameter(description = "ID") @PathVariable Integer id) {
        return ResultBean.success(payWithdrawalApplyService.deleteById(id));
    }
}