package fr.adrienbrault.idea.symfony2plugin.dic;

import fr.adrienbrault.idea.symfony2plugin.dic.container.ServiceInterface;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;

public class ContainerService {

    @Nullable
    private ServiceInterface service;
    private String name;
    private String className;
    private boolean isPrivate = false;
    private boolean isWeak = false;
    private Set<String> classVariants = new HashSet<>();

    public ContainerService(@NotNull ServiceInterface service, @Nullable String classResolved) {
        this.service = service;
        this.name = service.getId();
        this.className = classResolved != null ? classResolved : service.getClassName();
        this.isPrivate = !service.isPublic();
        this.isWeak = true;
    }

    public ContainerService(String name, String className) {
        this.name = name;
        this.className = className;
    }

    public ContainerService(String name, String className, boolean isWeak) {
        this(name, className);
        this.isWeak = isWeak;
    }

    public ContainerService(String name, String className, boolean isWeak, boolean isPrivate) {
        this(name, className, isWeak);
        this.isPrivate = isPrivate;
    }

    /**
     *
     * @return can be null, class, or a parameter name
     */
    @Nullable
    public String getClassName() {
        return className;
    }

    public void addClassName(@NotNull String className) {
        this.classVariants.add(className);
    }

    @NotNull
    public Set<String> getClassNames() {
        Set<String> variants = new HashSet<>();

        variants.add(className);
        variants.addAll(classVariants);

        return variants;
    }

    public boolean isWeak() {
        return isWeak;
    }

    public boolean isPrivate() {
        return isPrivate;
    }

    public String getName() {
        return name;
    }

    /**
     * legacy support
     */
    @Nullable
    public ServiceInterface getService() {
        return service;
    }
}


@@ -333,24 +333,38 @@
 ace service;
+%0A%0A    @NotNull
 %0A    private
@@ -372,24 +372,39 @@
 String name;
+%0A%0A    @Nullable
 %0A    private
@@ -911,32 +911,41 @@
 ontainerService(
+@NotNull 
 String name, Str
@@ -932,32 +932,42 @@
 ull String name,
+ @Nullable
  String classNam
@@ -1060,32 +1060,41 @@
 ontainerService(
+@NotNull 
 String name, Str
@@ -1222,16 +1222,25 @@
 Service(
+@NotNull 
 String n
@@ -1235,32 +1235,42 @@
 ull String name,
+ @Nullable
  String classNam
@@ -1758,24 +1758,60 @@
 shSet%3C%3E();%0A%0A
+        if(className != null) %7B%0A    
         vari
@@ -1823,32 +1823,43 @@
 add(className);%0A
+        %7D%0A%0A
         variants

fix nullable condition on service container build #754