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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
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 com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
import com.red.circle.other.infra.database.rds.service.team.TeamManagerInfoService;
import com.red.circle.other.inner.enums.team.TeamMemberRole;
import com.red.circle.other.inner.enums.team.TeamUserIdentity;
import org.junit.jupiter.api.Test;

class TeamUserIdentityQryExeTest {

  @Test
  void executeShouldReturnTouristWhenOwnerTeamIsClosed() {
    TeamMemberService teamMemberService = mock(TeamMemberService.class);
    TeamProfileService teamProfileService = mock(TeamProfileService.class);
    TeamManagerInfoService teamManagerInfoService = mock(TeamManagerInfoService.class);
    TeamUserIdentityQryExe exe = new TeamUserIdentityQryExe(teamMemberService, teamProfileService,
        teamManagerInfoService);

    AppUserIdCmd cmd = new AppUserIdCmd();
    cmd.setUserId(100L);
    TeamMember teamMember = new TeamMember()
        .setMemberId(100L)
        .setTeamId(200L)
        .setRole(TeamMemberRole.OWN);

    when(teamMemberService.getByMemberId(100L)).thenReturn(teamMember);
    when(teamManagerInfoService.checkManager(100L)).thenReturn(false);
    when(teamProfileService.checkStatusAvailable(200L)).thenReturn(false);

    assertEquals(TeamUserIdentity.TOURIST, exe.execute(cmd));
  }

  @Test
  void executeShouldReturnAgentWhenOwnerTeamIsAvailable() {
    TeamMemberService teamMemberService = mock(TeamMemberService.class);
    TeamProfileService teamProfileService = mock(TeamProfileService.class);
    TeamManagerInfoService teamManagerInfoService = mock(TeamManagerInfoService.class);
    TeamUserIdentityQryExe exe = new TeamUserIdentityQryExe(teamMemberService, teamProfileService,
        teamManagerInfoService);

    AppUserIdCmd cmd = new AppUserIdCmd();
    cmd.setUserId(100L);
    TeamMember teamMember = new TeamMember()
        .setMemberId(100L)
        .setTeamId(200L)
        .setRole(TeamMemberRole.OWN);

    when(teamMemberService.getByMemberId(100L)).thenReturn(teamMember);
    when(teamManagerInfoService.checkManager(100L)).thenReturn(false);
    when(teamProfileService.checkStatusAvailable(200L)).thenReturn(true);

    assertEquals(TeamUserIdentity.AGENT, exe.execute(cmd));
  }

  @Test
  void executeShouldReturnManagerWhenUserIsTeamManager() {
    TeamMemberService teamMemberService = mock(TeamMemberService.class);
    TeamProfileService teamProfileService = mock(TeamProfileService.class);
    TeamManagerInfoService teamManagerInfoService = mock(TeamManagerInfoService.class);
    TeamUserIdentityQryExe exe = new TeamUserIdentityQryExe(teamMemberService, teamProfileService,
        teamManagerInfoService);

    AppUserIdCmd cmd = new AppUserIdCmd();
    cmd.setUserId(100L);

    when(teamManagerInfoService.checkManager(100L)).thenReturn(true);

    assertEquals(TeamUserIdentity.MANAGER, exe.execute(cmd));
  }
}
