package com.red.circle.console.app.convertor.sys;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.red.circle.console.app.dto.clienobject.sys.ActivityConfigRewardsCO;
import com.red.circle.console.app.dto.cmd.app.sys.ActivityConfigBackConsoleQryCmd;
import com.red.circle.framework.core.convertor.ConvertorModel;
import com.red.circle.other.inner.model.cmd.sys.ActivityConfigBackQryCmd;
import com.red.circle.other.inner.model.dto.material.PropsActivityRewardConfigInfoDTO;
import com.red.circle.other.inner.model.dto.sys.ActivityConfigRewardsDTO;
import java.util.stream.Collectors;
import org.mapstruct.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zongpubin on 2023/10/10
 */
@Mapper(componentModel = ConvertorModel.SPRING)
public interface ActivityConfigAppConvertor {

  ActivityConfigBackQryCmd toActivityConfigBackQryCmd(ActivityConfigBackConsoleQryCmd query);

  default ActivityConfigRewardsCO toActivityConfigRewardsCO(ActivityConfigRewardsDTO reward) {
    return new ActivityConfigRewardsCO()
        .setResourceGroupId(reward.getResourceGroupId())
        .setRankRange(reward.getRankRange())
        .setRewards(
                reward.getRewards().stream().map(read -> {
                    ObjectMapper mapper = new ObjectMapper();
                    return mapper.convertValue(read, PropsActivityRewardConfigInfoDTO.class);
                }).collect(Collectors.toList()));
  }

}
