package com.red.circle.wallet.inner.service.freight.impl;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceService;
import com.red.circle.wallet.inner.convertor.FreightBalanceInnerConvertor;
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.stereotype.Service;

/**
 * 用户货运账户 服务类.
 *
 * @author pengliang on 2023/12/26
 */
@Service
@RequiredArgsConstructor
public class FreightBalanceClientServiceImpl implements FreightBalanceClientService {

  private final FreightBalanceService freightBalanceService;
  private final FreightBalanceInnerConvertor freightBalanceInnerConvertor;

  @Override
  public boolean checkClose(SysOriginPlatformEnum sysOrigin, Long userId) {
    return freightBalanceService.checkClose(sysOrigin, userId);
  }

  @Override
  public boolean existsBalance(Long userId) {
    return freightBalanceService.existsBalance(userId);
  }

  @Override
  public boolean incrCandyBalance(SysOriginPlatformEnum sysOrigin, Long userId,
      BigDecimal quantity) {
    return freightBalanceService.incrCandyBalance(sysOrigin, userId, quantity);
  }

  @Override
  public boolean decrCandyBalance(SysOriginPlatformEnum sysOrigin, Long userId,
      BigDecimal quantity) {
    return freightBalanceService.decrCandyBalance(sysOrigin, userId, quantity);
  }

  @Override
  public BigDecimal getAvailableBalance(Long userId) {
    return freightBalanceService.getAvailableBalance(userId);
  }

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

  @Override
  public List<UserFreightBalanceDTO> listFreightByBalanceGt1K(SysOriginPlatformEnum sysOrigin) {
    return freightBalanceInnerConvertor.toListUserFreightBalanceDTO(
        freightBalanceService.listFreightByBalanceGt1K(sysOrigin)
    );
  }

  @Override
  public BigDecimal getEarnPoints(Long userId) {
    return freightBalanceService.getEarnPoints(userId);
  }

  @Override
  public boolean checkDealer(SysOriginPlatformEnum sysOrigin, Long cmdOriginUserId) {
    return freightBalanceService.checkDealer(sysOrigin, cmdOriginUserId);
  }

  @Override
  public boolean checkDealerById( Long id) {
    return freightBalanceService.checkDealerById(id);
  }

  @Override
  public Integer selectSellerQuantity(Long freightId, String sysOrigin) {
    return freightBalanceService.selectSellerQuantity(freightId, sysOrigin);
  }

  @Override
  public UserFreightBalanceDTO getFreightBalance(Long userId) {
    return freightBalanceInnerConvertor.toUserFreightBalanceDTO(
        freightBalanceService.getFreightBalance(userId)
    );
  }

  @Override
  public UserFreightBalanceDTO getFreightBalanceById(Long id) {
    return freightBalanceInnerConvertor.toUserFreightBalanceDTO(
        freightBalanceService.getFreightBalance(id)
    );
  }

  @Override
  public Boolean checkFreightAgent(Long userId) {
    return freightBalanceService.checkFreightAgent(userId);
  }

}
