package com.red.circle.wallet.app.command.salaryDiamond.query;

import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.wallet.app.dto.clientobject.CommodityRunningWaterCO;
import com.red.circle.wallet.app.dto.cmd.DiamondRunningWaterQueryCmd;
import com.red.circle.wallet.infra.database.rds.entity.diamond.SalaryDiamondRunningWater;
import com.red.circle.wallet.infra.database.rds.service.diamond.SalaryDiamondRunningWaterService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 获取最近一个月流水-钻石
 *
 * @author lixiaofei on 2024/06/11
 */
@Component
@RequiredArgsConstructor
public class SalaryDiamondLatestOneMonthsFlowExe {

  private final SalaryDiamondRunningWaterService salaryDiamondRunningWaterService;

  public List<CommodityRunningWaterCO> execute(DiamondRunningWaterQueryCmd cmd) {
    List<SalaryDiamondRunningWater> runningWaters = salaryDiamondRunningWaterService
        .listUserLatestOneMonths(cmd.requiredReqUserId(), cmd.getType(), 20, cmd.getLastId());

    if (CollectionUtils.isEmpty(runningWaters)) {
      return CollectionUtils.newArrayList();
    }

    return runningWaters.stream().map(runningWater -> new CommodityRunningWaterCO()
        .setId(runningWater.getId())
        .setTitle(runningWater.getEventDesc())
        .setQuantity(runningWater.getAmount())
        .setType(runningWater.getType())
        .setCreateTime(runningWater.getCreateTime())
    ).collect(Collectors.toList());
  }
}
