public function buildCondition($actor_id, $config, $access = '@col(access)')
    {
        $store = $this->_repository->getStore();
        $viewer = $config->viewer;
        $where[] = 'CASE';
        $where[] = "WHEN $access IS NULL THEN 1";

        //for testing purpose
        //if($config->visible_to_leaders && $viewer->id && count($viewer->blockedIds) > 0)
        //    $where[] = "WHEN FIND_IN_SET(@col(id), '".$store->quoteValue($viewer->blockedIds->toArray())."') THEN 1";

        $where[] = "WHEN FIND_IN_SET('".self::GUEST."', $access) THEN 1";

        if ($viewer->id) {
            $where[] = "WHEN FIND_IN_SET('".self::REG."', $access) THEN 1";

            $where[] = 'WHEN FIND_IN_SET('.$viewer->id.", $access) THEN 1";

            if ($config->graph_check) {
                $leader_ids = $store->quoteValue($viewer->leaderIds->toArray());
                $follower_ids = $store->quoteValue($viewer->followerIds->toArray());
                $mutual_ids = $store->quoteValue($viewer->mutualIds->toArray());
                $admin_ids = $store->quoteValue($viewer->administratingIds->toArray());
                $is_viewer = "$actor_id = {$viewer->id}";

                $viewer_is_follower = "$is_viewer  OR $actor_id IN (".$leader_ids.')';
                $viewer_is_leader = "$is_viewer  OR $actor_id IN (".$follower_ids.')';
                $viewer_is_mutual = "$is_viewer  OR $actor_id IN (".$mutual_ids.')';
                $viewer_is_admin = "$is_viewer  OR $actor_id IN (".$admin_ids.')';
                $requestable = $this->_repository->isFollowable() ? '@col(allowFollowRequest) = 1' : 'FALSE';

                //if privacy set to follow, show the actor only if viewer is a follower or viewer is a leader or actor
                //accecpts follow request
                $where[] = "WHEN FIND_IN_SET('".self::FOLLOWER."',$access) THEN $viewer_is_follower OR $viewer_is_leader OR $requestable";
                $where[] = "WHEN FIND_IN_SET('".self::LEADER."',$access) THEN $viewer_is_leader";

                if ($config->visible_to_leaders) {
                    $where[] = "WHEN FIND_IN_SET('".self::MUTUAL."',$access) THEN $viewer_is_leader";
                    $where[] = "WHEN FIND_IN_SET('".self::ADMIN."',$access) THEN $viewer_is_admin OR $viewer_is_leader";
                } else {
                    $where[] = "WHEN FIND_IN_SET('".self::MUTUAL."',$access) THEN $viewer_is_mutual";
                    $where[] = "WHEN FIND_IN_SET('".self::ADMIN."',$access) THEN $viewer_is_admin";
                }
            }
        }

        $where[] = 'ELSE 0';
        $where[] = 'END';

        return implode(' ', $where);
    }