package cloud.nstart.terravault.ordinis.notifications.dispatcher;

import cloud.nstart.terravault.ordinis.notifications.channel.UserRef;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * Resolves a Keycloak subject (user UUID) to a {@link UserRef} for notification dispatch.
 *
 * <p>Backed by {@code UserDisplayService} (ordinis-rest-api module) injected via interface
 * to keep ordinis-notifications free of a direct compile-time dependency on rest-api.
 * In production the {@link UserDisplayServiceBridge} implementation is wired by the app module;
 * in unit tests a mock can be provided directly.
 */
public interface RecipientResolver {

  /**
   * Resolve user id → UserRef with email + locale. Returns empty when the user is unknown
   * (not in user_display_cache and Keycloak admin is not configured / unreachable).
   *
   * @param userId Keycloak subject (UUID string)
   * @return populated UserRef or empty
   */
  Optional<UserRef> resolveById(String userId);
}
