package com.seer.teach.pay.admin.refund.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.refund.controller.req.AdminRefundQueryReq;
import com.seer.teach.pay.admin.refund.controller.req.AdminRefundReviewReq;
import com.seer.teach.pay.admin.refund.controller.resp.AdminRefundResponse;
import com.seer.teach.pay.admin.refund.controller.resp.WechatRefundResp;
import com.seer.teach.pay.admin.refund.service.IAdminCoinRefundService;
import com.seer.teach.pay.entity.CoinRefundLogEntity;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

@RestController
@Tag(name = "管理端 - 退款申请")
@RequestMapping("/pay/refund")
public class AdminRefundServiceController {

    @Resource
    private IAdminCoinRefundService adminCoinRefundService;

    /**
     * 管理员查询退款申请列表
     */
    @PostMapping("/pageList")
    @SaCheckPermission("admin:refund:application:list")
    public ResultBean<PageListBean<AdminRefundResponse>> pageList(@RequestBody AdminRefundQueryReq request){
        return ResultBean.success(adminCoinRefundService.pageList(request));
    }

    /**
     * 管理员审核退款申请
     */
    @Operation(summary = "管理员审核退款申请")
    @PutMapping("/review")
    @SaCheckPermission("admin:refund:application:review")
    public ResultBean<Boolean> reviewRefundApplication(@RequestBody AdminRefundReviewReq adminRefundReviewReq) {
        return ResultBean.success(adminCoinRefundService.reviewRefund(adminRefundReviewReq));
    }

    /**
     * 根据退款编号查询退款结果
     */
    @Operation(summary = "根据退款编号获取退款结果")
    @GetMapping("/{refundSn}/result")
    @SaCheckPermission("admin:refund:application:result")
    public ResultBean<WechatRefundResp> getRefundResult(@PathVariable("refundSn") String refundSn) {
        return ResultBean.success(adminCoinRefundService.getRefundResult(refundSn));
    }

    /**
     * 管理员查询退款申请日志
     */
    @Operation(summary = "查询退款申请日志")
    @GetMapping("/{refundId}/logs")
    @SaCheckPermission("admin:refund:application:log")
    public ResultBean<List<CoinRefundLogEntity>> getRefundLogs(@PathVariable("refundId") Integer refundId){
        return ResultBean.success(adminCoinRefundService.getRefundLogsByRefundId(refundId));
    }

}