
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.ChargeConvert;
import com.wzj.soopin.transaction.domain.bo.ChargeBO;
import com.wzj.soopin.transaction.domain.po.Charge;
import com.wzj.soopin.transaction.domain.vo.ChargeVO;
import com.wzj.soopin.transaction.service.IChargeService;
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/charge")
@RequiredArgsConstructor
public class ChargeController {

    private final IChargeService service;
    private final ChargeConvert convert;

    @Operation(summary = "查询用户提现列表")
    @PostMapping("/list")
    @MemberFillMethod
    public R<IPage<ChargeVO>> list(@RequestBody ChargeBO bo, @RequestBody Page page) {
        Page<Charge> 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 ChargeBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Operation(summary = "获取用户提现详情")
    @GetMapping(value = "/{id}")
    @MemberFillMethod
    public R<ChargeVO> 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 ChargeBO bo) {
        service.save(convert.toPo(bo));
        return R.ok();
    }

    @Operation(summary = "审核用户提现")
    @Log(title = "审核用户提现", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public R audit(@RequestBody ChargeBO bo) {
        service.save(convert.toPo(bo));
        return R.ok();
    }


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