package com.cool.store.controller.webb;

import com.cool.store.dto.wallet.WithdrawApplicationDTO;
import com.cool.store.job.XxlJobHandler;
import com.cool.store.request.WithdrawApplicationPageRequest;
import com.cool.store.request.WithdrawApplicationRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.WithdrawApplicationResponse;
import com.cool.store.service.WithdrawApplicationService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 提现申请 Controller
 */
@RequestMapping("/pc/withdrawApplication")
@RestController
@Api(tags = "提现申请管理")
@Slf4j
public class WithdrawApplicationController {

    @Resource
    private WithdrawApplicationService withdrawApplicationService;
    @Resource
    XxlJobHandler xxlJobHandler;

    @PostMapping("/add")
    @ApiOperation("新增提现申请")
    public ResponseResult<Boolean> add(@Valid @RequestBody WithdrawApplicationRequest request) {
        return ResponseResult.success(withdrawApplicationService.add(request));
    }

    @PostMapping("/page")
    @ApiOperation("分页查询提现申请")
    public ResponseResult<PageInfo<WithdrawApplicationDTO>> page(@RequestBody WithdrawApplicationPageRequest request) {
        return ResponseResult.success(withdrawApplicationService.page(request));
    }

    @PostMapping("/confirmWithdraw")
    @ApiOperation("确认提现")
    public ResponseResult<Boolean> confirmWithdraw(@RequestParam Long id) {
        return ResponseResult.success(withdrawApplicationService.confirmWithdraw(id));
    }

    @ApiOperation("刷新提现单状态")
    @GetMapping("/refreshStatus")
    public ResponseResult<Boolean> refreshStatus() {
        xxlJobHandler.withdrawUpdate();
        return ResponseResult.success(Boolean.TRUE);
    }
}
