package org.raddatz.familienarchiv.user;

import lombok.RequiredArgsConstructor;
import org.raddatz.familienarchiv.user.AppUser;
import org.raddatz.familienarchiv.user.AppUserRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserSearchService {

    private static final int MAX_RESULTS = 10;

    private final AppUserRepository userRepository;

    public List<AppUser> search(String query) {
        if (query == null || query.isBlank()) return List.of();
        return userRepository.searchByEmailOrName(query.trim(), PageRequest.of(0, MAX_RESULTS));
    }
}
