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

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.wallet.inner.endpoint.freight.api.FreightGoldClientApi;
import com.red.circle.wallet.inner.model.cmd.AddFreightBalanceRunningWaterCmd;
import com.red.circle.wallet.inner.model.cmd.FreightAgentReviewCmd;
import com.red.circle.wallet.inner.model.cmd.FreightBalanceCmd;
import com.red.circle.wallet.inner.model.cmd.FreightBalanceRunningWaterCmd;
import com.red.circle.wallet.inner.model.cmd.UpdateFreightBalanceInfoCmd;
import com.red.circle.wallet.inner.model.cmd.UserFreightBalancePageQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExportQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserFreightSellerCmd;
import com.red.circle.wallet.inner.model.cmd.UserFreightSellerPageQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserFreightSellerRunningWaterPageQryCmd;
import com.red.circle.wallet.inner.model.dto.UserFreightBalanceDTO;
import com.red.circle.wallet.inner.model.dto.UserFreightBalanceRunningWaterDTO;
import com.red.circle.wallet.inner.model.dto.UserFreightSellerDTO;
import com.red.circle.wallet.inner.service.freight.FreightGoldClientService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
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/8/18
 */
@Validated
@RestController
@RequestMapping(value = FreightGoldClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class FreightGoldClientEndpoint implements FreightGoldClientApi {

  private final FreightGoldClientService freightGoldClientService;

  @Override
  public ResultResponse<Void> changeBalance(FreightBalanceRunningWaterCmd cmd) {
    freightGoldClientService.changeBalance(cmd);
    return ResultResponse.success();
  }

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


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

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

  @Override
  public ResultResponse<PageResult<UserFreightBalanceDTO>> pageFreight(
      UserFreightBalancePageQryCmd query) {
    return ResultResponse.success(freightGoldClientService.pageFreight(query));
  }

  @Override
  public ResultResponse<PageResult<UserFreightBalanceRunningWaterDTO>> pageRunningWater(
      UserFreightBalanceRunningWaterPageQryCmd query) {
    return ResultResponse.success(freightGoldClientService.pageRunningWater(query));
  }


  @Override
  public ResultResponse<PageResult<UserFreightBalanceRunningWaterDTO>> pageFreightSellerRunningWater(
      UserFreightSellerRunningWaterPageQryCmd query) {
    return ResultResponse.success(freightGoldClientService.pageFreightSellerRunningWater(query));
  }

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

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

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

  @Override
  public ResultResponse<Boolean> updateFreightBalance(FreightBalanceCmd cmd) {
    return ResultResponse.success(freightGoldClientService.updateFreightBalance(cmd));
  }

  @Override
  public ResultResponse<Void> addRunningWater(AddFreightBalanceRunningWaterCmd cmd) {
    freightGoldClientService.addRunningWater(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> updateSellerQuantity(UserFreightSellerCmd param) {

    return ResultResponse.success(freightGoldClientService.updateSellerQuantity(param));
  }

  @Override
  public ResultResponse<Void> deleteFreightBalance(Long userId) {
    freightGoldClientService.deleteFreightBalance(userId);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<Void> deleteFreightBalanceRunningWater(Long userId) {
    freightGoldClientService.deleteFreightBalanceRunningWater(userId);
    return ResultResponse.success();
  }

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

  @Override
  public ResultResponse<Map<Long, Long>> mapSellerQuantityByFreightIds(Set<Long> freightIds) {
    return ResultResponse.success(
        freightGoldClientService.mapSellerQuantityByFreightIds(freightIds));
  }


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


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

  @Override
  public ResultResponse<Void> addFreightAgentReview(FreightAgentReviewCmd cmd) {
    freightGoldClientService.addFreightAgentReview(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<UserFreightBalanceRunningWaterDTO>> listExportBalanceRunningWater(
      UserFreightBalanceRunningWaterExportQryCmd query) {
    return ResultResponse.success(freightGoldClientService.listExportBalanceRunningWater(
        query));
  }

  @Override
  public ResultResponse<PageResult<UserFreightSellerDTO>> pageFreightSeller(
      UserFreightSellerPageQryCmd query) {
    return ResultResponse.success(freightGoldClientService.pageFreightSeller(query));
  }

  @Override
  public ResultResponse<Void> removeFreightSeller(Long id) {
    freightGoldClientService.removeFreightSeller(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> updateFreightBalanceInfo(UpdateFreightBalanceInfoCmd cmd) {
    return ResultResponse.success(freightGoldClientService.updateFreightBalanceInfo(cmd));
  }

  @Override
  public ResultResponse<Map<Long, Long>> mapTransactionCountByUserIds(Set<Long> userIds) {
    return ResultResponse.success(freightGoldClientService.mapTransactionCountByUserIds(userIds));
  }

  @Override
  public ResultResponse<BigDecimal> getTotalAmountByCondition(Long userId, String startTime, String endTime, String rechargeType) {
    return ResultResponse.success(freightGoldClientService.getTotalAmountByCondition(userId, startTime, endTime, rechargeType));
  }
}
