package com.red.circle.wallet.adapter.app;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.IdLongCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.wallet.app.dto.clientobject.UserBankCardCO;
import com.red.circle.wallet.app.dto.cmd.UserBankCardAddCmd;
import com.red.circle.wallet.app.service.UserBankCardApiService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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;

/**
 * 用户银行卡服务.
 *
 * @author pengshigang on 2022/12/15
 * @eo.api-type http
 * @eo.groupName 钱包服务.银行卡
 * @eo.path /wallet/bank-card
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/bank-card", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserBankCardRestController extends BaseController {

  private final UserBankCardApiService userBankCardApiService;

  /**
   * 根据用户id获得银行卡里列表.
   *
   * @eo.name 根据用户id获得银行卡里列表.
   * @eo.url /list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list")
  public List<UserBankCardCO> listBankCard(AppExtCommand cmd) {
    return userBankCardApiService.listBankCard(cmd);
  }

  /**
   * 根据卡片id删除银行卡.
   *
   * @eo.name 根据卡片id删除银行卡.
   * @eo.url /delete
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/delete")
  public void deleteById(@RequestBody @Validated IdLongCmd cmd) {
    userBankCardApiService.deleteById(cmd);
  }

  /**
   * 使用银行卡.
   *
   * @eo.name 使用银行卡.
   * @eo.url /use
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/use")
  public void use(@RequestBody @Validated IdLongCmd cmd) {
    userBankCardApiService.use(cmd);
  }

  /**
   * 添加用户银行卡.
   *
   * @eo.name 添加用户银行卡.
   * @eo.url /add
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/add")
  public void add(@RequestBody @Validated UserBankCardAddCmd cmd) {
    userBankCardApiService.add(cmd);
  }

}
