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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.convertor.material.PropsMaterialAppConvertor;
import com.red.circle.other.app.dto.clientobject.activity.ActivityResourceCO;
import com.red.circle.other.app.dto.clientobject.task.CheckInRewardListCO;
import com.red.circle.other.domain.gateway.props.ActivitySourceGroupGateway;
import com.red.circle.other.infra.database.cache.service.other.CheckInCacheService;
import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum;
import java.util.List;
import java.util.Optional;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 每日打卡奖励-信息.
 *
 * @author zongpubin on 2023/10/19
 */
@Service
@AllArgsConstructor
public class CheckInRewardQryExe {

  private final PropsMaterialAppConvertor propsMaterialAppConvertor;
  private final CheckInCacheService checkInCacheService;
  private final ActivitySourceGroupGateway activitySourceGroupGateway;

  public CheckInRewardListCO execute(AppExtCommand cmd) {

    List<ActivityResourceCO> rewards = propsMaterialAppConvertor
        .toActivityResourceCOList(activitySourceGroupGateway
            .listActivityResource(cmd.requireReqSysOriginEnum(),
                PropsActivityTypeEnum.DAILY_REGISTER));

    return new CheckInRewardListCO()
        .setDays(Optional.ofNullable(checkInCacheService.getCheckInDays(cmd.getReqUserId()))
            .orElse(0))
        .setRewards(rewards);
  }

}
