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


import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.app.dto.clientobject.team.TeamQuitApplyInfoCO;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamApplicationProcessService;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService;
import com.red.circle.other.inner.asserts.team.TeamErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 获取用户退出申请信息.
 *
 * @author pengliang on 2023/01/09
 */
@Component
@RequiredArgsConstructor
public class TeamQuitApplyInfoQryExe {

  private final TeamMemberService teamMemberService;
  private final TeamApplicationProcessService teamApplicationProcessService;

  public TeamQuitApplyInfoCO execute(AppExtCommand cmd) {
    TeamMember teamMember = teamMemberService.getByMemberId(cmd.getReqUserId());
    ResponseAssert.notNull(TeamErrorCode.NOT_TEAM_MEMBER, teamMember);
    return new TeamQuitApplyInfoCO()
        .setQuitApplyMessageId(
            teamApplicationProcessService.getQuitWaitApplyId(cmd.getReqUserId()))
        .setRole(teamMember.getRole().name());
  }
}
