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

import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService;
import java.util.Objects;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 获取团队中角色.
 *
 * @author pengliang on 2022/12/30
 */
@Component
@RequiredArgsConstructor
public class TeamMemberRoleQryExe {

  private final TeamMemberService teamMemberService;

  public String execute(AppIdLongCmd cmd) {
    return Optional.ofNullable(teamMemberService.getMember(cmd.getId(), cmd.getReqUserId()))
        .map(TeamMember::getRole)
        .map(Objects::toString)
        .orElse("");
  }
}
