class MaintenanceStateHelper {

  public Resource.Type guessOperationLevel(RequestResourceFilter filter) {
    Resource.Type result;
    if (filter == null) {
      // CLUSTER can be assumed to be the default level if no ResourceFilter
      // is specified, because for any other resource operation
      // a ResourceFilter is mandatory.
      result = Resource.Type.Cluster;
    } else {
      boolean serviceDefined = filter.getServiceName() != null;
      boolean componentDefined = filter.getComponentName() != null;
      boolean hostsDefined = filter.getHostNames() != null
          && filter.getHostNames().size() > 0;

      if (hostsDefined & componentDefined) {
        result = Resource.Type.HostComponent;
      } else if (!serviceDefined & hostsDefined) {
        result = Resource.Type.Host;
      } else if (serviceDefined & !hostsDefined) {
        // This option also includes resource filters
        // that target service on few hosts
        result = Resource.Type.Service;
      } else { // Absolute fallback
        // Cluster level should be a good option for any unsure cases
        // Cluster-level actions only
        result = Resource.Type.Cluster;
      }
    }
    return result;
  }

  @Inject public  MaintenanceStateHelper(Injector injector);

}