package com.red.circle.other.app.command.task.query;

import com.google.common.collect.Lists;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.task.DailyTaskStorageCO;
import com.red.circle.other.infra.database.mongo.entity.task.DailyTaskStorage;
import com.red.circle.other.infra.database.mongo.service.task.DailyTaskStorageService;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 语音房间任务完成列表.
 *
 * @author pengliang on 2021/5/8
 */
@Component
@RequiredArgsConstructor
public class VoiceTaskCompletedTaskListQryExe {

  private final DailyTaskStorageService dailyTaskStorageService;

  public List<DailyTaskStorageCO> execute(AppExtCommand cmd) {

    List<DailyTaskStorage> dailyTasks = dailyTaskStorageService
        .getByUserId(cmd.getReqUserId());

    if (CollectionUtils.isEmpty(dailyTasks)) {
      return Lists.newArrayList();
    }

    return dailyTasks.stream().map(dailyTaskStorage -> new DailyTaskStorageCO()
        .setUserId(dailyTaskStorage.getUserId())
        .setStatus(dailyTaskStorage.getStatus().name())
        .setTaskType(dailyTaskStorage.getTaskType())
    ).toList();
  }
}
