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

import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.other.app.dto.cmd.user.material.UserSwitchBadgeCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;

import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 用户切换使用徽章.
 *
 * @author pengliang on 2021/3/23
 */
@Component
@RequiredArgsConstructor
public class UserSwitchBadgeCmdExe {

  private final UserProfileGateway userProfileGateway;

  public void execute(UserSwitchBadgeCmd cmd) {
    List<Long> badgeIds = cmd.filterNullToList();
  //  Set<Long> badgeIds = cmd.filterNullToSet();

    if (CollectionUtils.isEmpty(badgeIds)) {
      userProfileGateway
          .removeUserAllWearBadge(cmd.getReqUserId(), cmd.getReqSysOrigin().getOrigin());
      return;
    }
    userProfileGateway.updateUserWearBadge(cmd.getReqUserId(), cmd.getReqSysOrigin().getOrigin(),
        badgeIds);
  }

}
