package com.red.circle.wallet.inner.endpoint.wallet;

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.wallet.infra.database.rds.service.WalletGoldBalanceService;
import com.red.circle.wallet.inner.endpoint.bank.api.UserBankBalanceClientApi;
import com.red.circle.wallet.inner.model.cmd.UserBankBalanceDecrCmd;
import com.red.circle.wallet.inner.model.cmd.UserBankBalanceIncrCmd;
import com.red.circle.wallet.inner.model.cmd.UserBankBalanceQryCmd;
import com.red.circle.wallet.inner.model.dto.BankBalanceDTO;
import com.red.circle.wallet.inner.model.dto.UserBankBalanceDTO;
import com.red.circle.wallet.inner.service.wallet.UserBankBalanceClientService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户银行卡余额.
 *
 * @author pengliang on 2023/9/22
 */
@Validated
@RestController
@RequestMapping(value = UserBankBalanceClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class UserBankBalanceClientEndpoint implements UserBankBalanceClientApi {

  private final UserBankBalanceClientService userBankBalanceClientService;
  private final WalletGoldBalanceService walletGoldBalanceService;


  @Override
  public ResultResponse<Boolean> exists(Long userId) {
    return ResultResponse.success(userBankBalanceClientService.exists(userId));
  }

  @Override
  public ResultResponse<Boolean> incr(UserBankBalanceIncrCmd cmd) {
    return ResultResponse.success(userBankBalanceClientService.incr(cmd));
  }

  @Override
  public ResultResponse<BankBalanceDTO> decr(UserBankBalanceDecrCmd cmd) {
    return ResultResponse.success(userBankBalanceClientService.decr(cmd));
  }

  @Override
  public ResultResponse<BankBalanceDTO> getBalance(Long userId) {
    return ResultResponse.success(userBankBalanceClientService.getBalance(userId));
  }  @Override
  public ResultResponse<Long> getTotalBalance(Long userId) {
    return ResultResponse.success(walletGoldBalanceService.getBalanceTotal(userId));
  }


  @Override
  public ResultResponse<List<UserBankBalanceDTO>> listBalance(UserBankBalanceQryCmd query) {
    return ResultResponse.success(userBankBalanceClientService.listBalance(query));
  }

}
