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

import com.red.circle.other.app.common.props.BadgeCommon;
import com.red.circle.other.app.dto.cmd.material.BadgeProgressRateCmd;
import java.math.BigDecimal;
import java.util.Objects;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 获取徽章进度情况.
 *
 * @author pengliang on 2021/4/7
 */
@Component
@RequiredArgsConstructor
public class BadgeProgressRateQryExe {

  private final BadgeCommon badgeCommon;

  public BigDecimal execute(BadgeProgressRateCmd cmd) {
    return Optional
        .ofNullable(badgeCommon.getProgressRate(Objects.isNull(cmd.getUserId()) ? cmd.requiredReqUserId() : cmd.getUserId(), cmd.getBadgeKey()))
        .orElse(BigDecimal.ZERO);
  }

}
