package io.scalecube.services;

import io.scalecube.services.annotations.Service;
import io.scalecube.services.annotations.ServiceMethod;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ServiceScanner {

  private ServiceScanner() {
    // Do not instantiate
  }

  /**
   * Scans {@code ServiceInfo} and builds list of {@code ServiceRegistration}-s
   *
   * @param serviceInfo service info instance
   * @return list of {@code ServiceRegistration}-s
   */
  public static List<ServiceRegistration> scanServiceInfo(ServiceInfo serviceInfo) {
    return Arrays.stream(serviceInfo.serviceInstance().getClass().getInterfaces())
        .map(serviceInterface -> new InterfaceInfo(serviceInterface, serviceInfo.tags()))
        .filter(interfaceInfo -> interfaceInfo.serviceInterface.isAnnotationPresent(Service.class))
        .map(
            interfaceInfo -> {
              Class<?> serviceInterface = interfaceInfo.serviceInterface;
              Map<String, String> serviceTags = interfaceInfo.tags;
              String namespace = Reflect.serviceName(serviceInterface);
              List<ServiceMethodDefinition> actions =
                  Arrays.stream(serviceInterface.getMethods())
                      .filter(method -> method.isAnnotationPresent(ServiceMethod.class))
                      .map(method -> new ServiceMethodDefinition(Reflect.methodName(method)))
                      .collect(Collectors.toList());
              return new ServiceRegistration(namespace, serviceTags, actions);
            })
        .collect(Collectors.toList());
  }

  /** Tuple class. Contains service interface along with tags map. */
  private static class InterfaceInfo {
    private final Class<?> serviceInterface;
    private final Map<String, String> tags;

    private InterfaceInfo(Class<?> serviceInterface, Map<String, String> tags) {
      this.serviceInterface = serviceInterface;
      this.tags = tags;
    }
  }
}

@@ -410,24 +410,25 @@
 istration%7D-s
+.
 %0A   *%0A   * @

add period to javadoc