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

import com.red.circle.common.business.dto.cmd.IdLongCmd;
import com.red.circle.console.app.dto.clienobject.user.UserBankCardCO;
import com.red.circle.console.app.service.app.user.UserBankCardBackService;
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.UserBankCardBackQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserBankCardCmd;
import com.red.circle.wallet.inner.model.dto.UserBankCardDTO;
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 pengshigang
 * @since 2022-12-7
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/user/bank-card")
public class UserBankCardRestController extends BaseController {

  private final UserBankCardBackService userBankCardBackService;

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

  /**
   * 通过银行卡列表.
   */
  @GetMapping("/pass-list")
  public List<UserBankCardDTO> listPassBankCard(Long userId) {
    return userBankCardBackService.listPassBankCard(userId);
  }

  /**
   * 用户银行卡分页.
   */
  @GetMapping("/page")
  public PageResult<UserBankCardCO> pageQuery(UserBankCardBackQryCmd query) {
    return userBankCardBackService.pageQuery(query);
  }

  /**
   * 修改用户银行卡.
   */
  @PostMapping("/update")
  public void update(@RequestBody @Validated UserBankCardCmd param) {
    param.setUpdateUser(param.getReqUserId());
    param.setUpdateTime(TimestampUtils.now());
    userBankCardBackService.update(param);
  }

  /**
   * 添加用户银行卡.
   */
  @PostMapping("/add")
  public void add(@RequestBody @Validated UserBankCardCmd param) {
    param.setCreateUser(param.getReqUserId());
    param.setCreateTime(TimestampUtils.now());
    userBankCardBackService.add(param);
  }

  /**
   * 审核驳回用户银行卡.
   */
  @PostMapping("/not-pass")
  public void notPass(@RequestBody Set<Long> ids) {
    userBankCardBackService.notPass(ids, getReqUserId());
  }

  /**
   * 审核通过用户银行卡.
   */
  @PostMapping("/pass")
  public void pass(@RequestBody Set<Long> ids) {
    userBankCardBackService.pass(ids, getReqUserId());
  }

  /**
   * 根据银行id删除用户银行卡.
   */
  @GetMapping("/delete/{id}")
  public void deleteById(@PathVariable("id") Long id) {
    userBankCardBackService.deleteById(id, getReqUserId());
  }

  /**
   * 切换使用中的银行卡.
   */
  @GetMapping("/use/{id}")
  public void use(@PathVariable("id") Long id) {
    userBankCardBackService.use(id, getReqUserId());
  }

}
