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

import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.other.app.dto.clientobject.user.user.UserLevelCO;
import com.red.circle.other.domain.model.user.UserConsumptionLevel;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 获取用户财富等级和魅力等级.
 *
 * @author zongpubin on 2023/4/25
 */
@Component
@RequiredArgsConstructor
public class UserConsumptionLevelQryExe {

  private final UserProfileGateway userProfileGateway;

  public UserLevelCO execute(AppUserIdCmd cmd) {
    UserConsumptionLevel level = userProfileGateway.getUserConsumptionLevel(
        cmd.requireReqSysOriginEnum(), cmd.getUserId());
    if (Objects.isNull(level)) {
      return new UserLevelCO()
          .setWealthLevel(0)
          .setCharmLevel(0);
    }
    return new UserLevelCO()
        .setWealthLevel(level.getWealthLevel())
        .setCharmLevel(level.getCharmLevel());
  }

}
