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

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.wallet.inner.endpoint.freight.api.FreightBalanceClientApi;
import com.red.circle.wallet.inner.model.dto.UserFreightBalanceDTO;
import com.red.circle.wallet.inner.service.freight.FreightBalanceClientService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
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/12/26
 */
@Validated
@RestController
@RequestMapping(value = FreightBalanceClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class FreightBalanceClientEndpoint implements FreightBalanceClientApi {

  private final FreightBalanceClientService freightBalanceClientService;

  @Override
  public ResultResponse<Boolean> checkClose(SysOriginPlatformEnum sysOrigin, Long userId) {
    return ResultResponse.success(
        freightBalanceClientService.checkClose(sysOrigin, userId)
    );
  }

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

  @Override
  public ResultResponse<Boolean> incrCandyBalance(SysOriginPlatformEnum sysOrigin, Long userId,
      BigDecimal quantity) {
    return ResultResponse.success(
        freightBalanceClientService.incrCandyBalance(sysOrigin, userId, quantity)
    );
  }

  @Override
  public ResultResponse<Boolean> decrCandyBalance(SysOriginPlatformEnum sysOrigin, Long userId,
      BigDecimal quantity) {
    return ResultResponse.success(
        freightBalanceClientService.decrCandyBalance(sysOrigin, userId, quantity)
    );
  }

  @Override
  public ResultResponse<BigDecimal> getAvailableBalance(Long userId) {
    return ResultResponse.success(
        freightBalanceClientService.getAvailableBalance(userId)
    );
  }

  @Override
  public ResultResponse<Set<Long>> listUserIdBySysOrigin(SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        freightBalanceClientService.listUserIdBySysOrigin(sysOrigin)
    );
  }

  @Override
  public ResultResponse<List<UserFreightBalanceDTO>> listFreightByBalanceGt1K(
      SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        freightBalanceClientService.listFreightByBalanceGt1K(sysOrigin)
    );
  }

  @Override
  public ResultResponse<BigDecimal> getEarnPoints(Long userId) {
    return ResultResponse.success(
        freightBalanceClientService.getEarnPoints(userId)
    );
  }

  @Override
  public ResultResponse<Boolean> checkDealer(SysOriginPlatformEnum sysOrigin, Long userId) {
    return ResultResponse.success(
        freightBalanceClientService.checkDealer(sysOrigin, userId)
    );
  }

  @Override
  public ResultResponse<Boolean> checkDealerById(Long id) {
    return ResultResponse.success(
        freightBalanceClientService.checkDealerById(id)
    );
  }

  @Override
  public ResultResponse<Integer> selectSellerQuantity(Long freightId, String sysOrigin) {
    return ResultResponse.success(
        freightBalanceClientService.selectSellerQuantity(freightId, sysOrigin)
    );
  }

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

  @Override
  public ResultResponse<UserFreightBalanceDTO> getFreightBalance(Long userId) {
    return ResultResponse.success(
        freightBalanceClientService.getFreightBalance(userId)
    );
  }

  @Override
  public ResultResponse<UserFreightBalanceDTO> getFreightBalanceById(Long id) {
    return ResultResponse.success(
        freightBalanceClientService.getFreightBalanceById(id)
    );
  }
}
