package com.red.circle.console.adapter.app.user;

import com.red.circle.console.app.dto.clienobject.user.UserWithdrawInfoCO;
import com.red.circle.console.app.service.app.user.UserWithdrawInfoBackService;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.tool.core.date.TimestampUtils;
import com.red.circle.wallet.inner.model.cmd.UserWithdrawInfoBackQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserWithdrawInfoCmd;
import com.red.circle.wallet.inner.model.dto.UserWithdrawInfoDTO;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户提现信息 前端控制器.
 * </p>
 *
 * @author tf
 * @since 2025-01-09
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/user/withdraw-info")
public class UserWithdrawInfoRestController extends BaseController {

  private final UserWithdrawInfoBackService userWithdrawInfoBackService;

  /**
   * 列表查询.
   */
  @GetMapping("/list/user-id/{id}")
  public List<UserWithdrawInfoCO> listByUserId(@PathVariable("id") Long id) {
    return userWithdrawInfoBackService.listByUserId(id);
  }

  /**
   * 通过的提现信息列表.
   */
  @GetMapping("/pass-list")
  public List<UserWithdrawInfoDTO> listPassWithdrawInfo(Long userId) {
    return userWithdrawInfoBackService.listPassWithdrawInfo(userId);
  }

  /**
   * 用户提现信息分页.
   */
  @GetMapping("/page")
  public PageResult<UserWithdrawInfoCO> pageQuery(UserWithdrawInfoBackQryCmd query) {
    return userWithdrawInfoBackService.pageQuery(query);
  }

  /**
   * 修改用户提现信息.
   */
  @PostMapping("/update")
  public void update(@RequestBody @Validated UserWithdrawInfoCmd param) {
    param.setUpdateUser(param.getReqUserId());
    param.setUpdateTime(TimestampUtils.now());
    userWithdrawInfoBackService.update(param);
  }

  /**
   * 添加用户提现信息.
   */
  @PostMapping("/add")
  public void add(@RequestBody @Validated UserWithdrawInfoCmd param) {
    param.setCreateUser(param.getReqUserId());
    param.setCreateTime(TimestampUtils.now());
    userWithdrawInfoBackService.add(param);
  }

  /**
   * 审核驳回用户提现信息.
   */
  @PostMapping("/not-pass")
  public void notPass(@RequestBody Set<Long> ids) {
    userWithdrawInfoBackService.notPass(ids, getReqUserId());
  }

  /**
   * 审核通过用户提现信息.
   */
  @PostMapping("/pass")
  public void pass(@RequestBody Set<Long> ids) {
    userWithdrawInfoBackService.pass(ids, getReqUserId());
  }

  /**
   * 根据提现信息id删除用户提现信息.
   */
  @GetMapping("/delete/{id}")
  public void deleteById(@PathVariable("id") Long id) {
    userWithdrawInfoBackService.deleteById(id, getReqUserId());
  }

  /**
   * 切换使用中的提现信息.
   */
  @GetMapping("/use/{id}")
  public void use(@PathVariable("id") Long id) {
    userWithdrawInfoBackService.use(id, getReqUserId());
  }

}
