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

import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.other.infra.database.rds.service.sys.AdministratorService;
import com.red.circle.other.infra.database.rds.service.user.user.RelationshipFriendService;
import java.util.Objects;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 检测是否是好友关系.
 *
 * @author pengliang on 2021/5/7
 */
@Component
@RequiredArgsConstructor
public class FriendCheckQryExe {

  private final AdministratorService administratorService;
  private final RelationshipFriendService relationshipFriendService;

  public Boolean execute(AppUserIdCmd cmd) {
    Boolean isAdmin = administratorService.existsAvailable(
        Set.of(cmd.requiredReqUserId(), cmd.getUserId()));

    if (Objects.equals(isAdmin, Boolean.TRUE)) {
      return Boolean.TRUE;
    }

    return relationshipFriendService
        .checkFriend(cmd.requiredReqUserId(), cmd.getUserId());
  }

}
