
package com.wzj.soopin.transaction.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.annotation.MemberFillMethod;
import com.wzj.soopin.transaction.convert.WithdrawConvert;
import com.wzj.soopin.transaction.domain.bo.WithdrawBO;
import com.wzj.soopin.transaction.domain.po.Withdraw;
import com.wzj.soopin.transaction.domain.vo.WithdrawVO;
import com.wzj.soopin.transaction.service.IWithdrawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.*;

/**
 * 用户封禁
 */
@Tag(name = "提现")
@RestController
@RequestMapping("/trans/withdraw")
@RequiredArgsConstructor
public class WithdrawController {

    private final IWithdrawService service;
    private final WithdrawConvert convert;

    @Operation(summary = "查询提现列表")
    @PostMapping("/list")
    @MemberFillMethod
    public R<IPage<WithdrawVO>> list(@RequestBody WithdrawBO bo, @RequestBody Page page) {
        Page<Withdraw> pages = service.page(page, bo.toWrapper());
        return R.ok(convert.toVO(pages));
    }

    @Operation(summary = "新增提现")
    @Log(title = "新增提现", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody WithdrawBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Operation(summary = "获取提现详情")
    @GetMapping(value = "/{id}")
    @MemberFillMethod
    public R<WithdrawVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

    @Operation(summary = "审批提现")
    @Log(title = "审批提现", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R update(@RequestBody WithdrawBO bo) {
        return R.ok(service.audit(bo));
    }


    @Operation(summary = "删除提现")
    @Log(title = "删除提现", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Object> remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }
}
