package com.red.circle.wallet.infra.database.rds.service.freight;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.mybatis.service.BaseService;
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalanceRunningWater;
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.UserFreightSellerRunningWaterPageQryCmd;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 用户货运账户流水 服务类.
 * </p>
 *
 * @author pengshigang
 * @since 2021-07-06
 */
public interface FreightBalanceRunningWaterService extends BaseService<FreightBalanceRunningWater> {

  /**
   * 用户货运单.
   *
   * @param userId 用户id
   * @param lastId 最后一条记录id
   * @return ignore
   */
  List<FreightBalanceRunningWater> flowByUserId(Long userId, Long acceptUserId, Integer type, Long lastId);


  /**
   * 用户货运单.
   *
   * @param sellerId 用户id
   * @param lastId   最后一条记录id
   * @return ignore
   */
  List<FreightBalanceRunningWater> flowBySellerId(Long sellerId, Long lastId);

  /**
   * 删除记录
   */
  void deleteByUserId(Long userId);

  /**
   * 用户货运单.
   *
   * @param userId      用户id
   * @param lastId      最后一条记录id
   * @param currentDate 年月
   * @return ignore
   */
  List<FreightBalanceRunningWater> flowByUserIdAndDate(Long userId, Long lastId,
      String currentDate);

  PageResult<FreightBalanceRunningWater> pageRunningWater(
      UserFreightBalanceRunningWaterPageQryCmd query);

  PageResult<FreightBalanceRunningWater> pageFreightSellerRunningWater(
      UserFreightSellerRunningWaterPageQryCmd query);

  List<FreightBalanceRunningWater> listExportBalanceRunningWater(
      UserFreightBalanceRunningWaterExportQryCmd query);

  /**
   * 批量统计用户交易次数（type=1的记录数）.
   *
   * @param userIds 用户ID集合
   * @return 用户ID -> 交易次数
   */
  boolean existsRecord(String txId);

  Map<Long, Long> countTransactionsByUserIds(Set<Long> userIds);

  /**
   * 查询用户指定时间和类型的总金额.
   *
   * @param userId 用户ID
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param rechargeType 充值类型
   * @return 总金额
   */
  BigDecimal sumAmountByCondition(Long userId, String startTime, String endTime, String rechargeType);
}
