package com.red.circle.wallet.app.command.diamond.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.DiamondRunningWater;
import com.red.circle.wallet.infra.database.rds.service.diamond.DiamondRunningWaterService;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 获取最近一个月流水-钻石
 *
 * @author pengshigang on 2023/7/21
 */
@Component
@RequiredArgsConstructor
public class DiamondLatestOneMonthsFlowExe {

  private final DiamondRunningWaterService diamondRunningWaterService;

  public List<CommodityRunningWaterCO> execute(DiamondRunningWaterQueryCmd cmd) {
    List<DiamondRunningWater> runningWaters = diamondRunningWaterService
        .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.getOriginDesc())
        .setQuantity(runningWater.getQuantity())
        .setType(runningWater.getType())
        .setCreateTime(runningWater.getCreateTime())
    ).collect(Collectors.toList());
  }
}
