package fr.adrienbrault.idea.symfony2plugin.assistant.signature;

import com.intellij.openapi.project.Project;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
import fr.adrienbrault.idea.symfony2plugin.dic.XmlServiceParser;
import fr.adrienbrault.idea.symfony2plugin.doctrine.EntityHelper;
import fr.adrienbrault.idea.symfony2plugin.form.util.FormUtil;
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.Collection;

public class PhpTypeSignatureTypes {

    public static PhpTypeSignatureInterface[] DEFAULT_PROVIDER = new PhpTypeSignatureInterface[] {
        new ServiceType(),
        new ClassType(),
        new FormTypesType()
    };

    private static class ServiceType implements PhpTypeSignatureInterface {

        @Nullable
        public Collection<? extends PhpNamedElement> getByParameter(Project project, String parameter) {
            String serviceClass = ServiceXmlParserFactory.getInstance(project, XmlServiceParser.class).getServiceMap().getMap().get(parameter);
            if (null == serviceClass) {
                return null;
            }

            return PhpIndex.getInstance(project).getAnyByFQN(serviceClass);
        }

        @NotNull
        public String getName() {
            return "Service";
        }

    }

    private static class ClassType implements PhpTypeSignatureInterface {

        @Nullable
        public Collection<? extends PhpNamedElement> getByParameter(Project project, String parameter) {
            return PhpIndex.getInstance(project).getAnyByFQN(parameter.startsWith("\\") ? parameter : "\\" + parameter);
        }

        @NotNull
        public String getName() {
            return "Class";
        }

    }

    private static class FormTypesType implements PhpTypeSignatureInterface {

        @Nullable
        public Collection<? extends PhpNamedElement> getByParameter(Project project, String parameter) {
            return Arrays.asList(FormUtil.getFormTypeToClass(project, parameter));
        }

        @NotNull
        public String getName() {
            return "FormType";
        }

    }

}

@@ -446,16 +446,81 @@
 rmUtil;%0A
+import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;%0A
 import f
@@ -592,16 +592,16 @@
 actory;%0A
-
 import o
@@ -949,16 +949,80 @@
 esType()
+,%0A        new InterfaceType(),%0A        new ClassInterfaceType(),
 %0A    %7D;%0A
@@ -1882,27 +1882,882 @@
 project).get
-Any
+ClassesByFQN(parameter.startsWith(%22%5C%5C%22) ? parameter : %22%5C%5C%22 + parameter);%0A        %7D%0A%0A        @NotNull%0A        public String getName() %7B%0A            return %22Class%22;%0A        %7D%0A%0A    %7D%0A%0A    private static class ClassInterfaceType implements PhpTypeSignatureInterface %7B%0A%0A        @Nullable%0A        public Collection%3C? extends PhpNamedElement%3E getByParameter(Project project, String parameter) %7B%0A            return Arrays.asList(PhpElementsUtil.getClassInterface(project, parameter));%0A        %7D%0A%0A        @NotNull%0A        public String getName() %7B%0A            return %22ClassInterface%22;%0A        %7D%0A%0A    %7D%0A%0A    private static class InterfaceType implements PhpTypeSignatureInterface %7B%0A%0A        @Nullable%0A        public Collection%3C? extends PhpNamedElement%3E getByParameter(Project project, String parameter) %7B%0A            return PhpIndex.getInstance(project).getInterfaces
 ByFQN(parame
@@ -2884,37 +2884,41 @@
         return %22
-Class
+Interface
 %22;%0A        %7D%0A%0A  

add new type provider "Interface" and "ClassInterface" #254