// Path: annotation/src/main/java/link/anyauto/smartkey/annotation/AnnotationConstants.java
// public class AnnotationConstants {
//     public static final String SUFFIX_INTENT_BUILDER = "IBuilder";
//     public static final String SUFFIX_SHARED_PREFERENCES_BUILDER = "SPBuilder";
//     public static final String SUFFIX_ACTIVITY_TARGET = "ATarget";
//     public static final String SUFFIX_SERVICE_TARGET = "STarget";
// 
//     public static final String TARGET_TYPE_ACTIVITY = "activity";
//     public static final String TARGET_TYPE_ACTIVITY_ALIAS = "activity-alias";
//     public static final String TARGET_TYPE_SERVICE = "service";
// }
// 
// Path: apt/src/main/java/link/anyauto/smartkey/apt/manifestanalyzer/TargetDescriptor.java
// public class TargetDescriptor {
//     public String name;
//     public String aliasName;
//     public ArrayList<TargetFilter> filters = new ArrayList<>();
// 
//     public String getSimpleName() {
//         return name.substring(name.lastIndexOf('.') + 1);
//     }
// }
// 
// Path: apt/src/main/java/link/anyauto/smartkey/apt/manifestanalyzer/TargetFilter.java
// public class TargetFilter {
//     public ArrayList<String> categories = new ArrayList<>();
//     public ArrayList<String> actions = new ArrayList<>();
// }


import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.util.ArrayList;
import java.util.HashMap;
import javax.lang.model.element.Modifier;
import link.anyauto.smartkey.annotation.AnnotationConstants;
import link.anyauto.smartkey.annotation.SmartTarget;
import link.anyauto.smartkey.apt.manifestanalyzer.TargetDescriptor;
import link.anyauto.smartkey.apt.manifestanalyzer.TargetFilter;
    }

    public void addType(TargetDescriptor des) {
        TypeSpec.Builder type = types.get(des.name);
        if (type == null) {
            ClassName activityType = ClassName.bestGuess(des.name);
            ClassName builderName = ClassName.bestGuess(des.name + AnnotationConstants.SUFFIX_ACTIVITY_TARGET);
            addType(des.getSimpleName(), des.name, activityType, builderName, null);
        }
        if (des.filters.isEmpty() || des.filters.get(0).actions.isEmpty()) {
            return;
        }
        for (TargetFilter filter : des.filters) {
            for(String action : filter.actions) {
                if("android.intent.action.MAIN".equals(action))
                    continue;
                addGoActivityMethod(des.name,
                        "goWithAction_" + action.replace('.', '_').replace(" ", "").toUpperCase(),
                        action, filter.categories);
                addGoActivityMethod(des.name,
                        "goForResultWithAction_" + action.replace('.', '_').replace(" ", "").toUpperCase(),
                        action, filter.categories);
            }
        }
    }

    public void addAliasType(TargetDescriptor target) {
        if (target.filters.isEmpty() || target.filters.get(0).actions.isEmpty()) {
            return;
        }
// Path: annotation/src/main/java/link/anyauto/smartkey/annotation/AnnotationConstants.java
// public class AnnotationConstants {
//     public static final String SUFFIX_INTENT_BUILDER = "IBuilder";
//     public static final String SUFFIX_SHARED_PREFERENCES_BUILDER = "SPBuilder";
//     public static final String SUFFIX_ACTIVITY_TARGET = "ATarget";
//     public static final String SUFFIX_SERVICE_TARGET = "STarget";
// 
//     public static final String TARGET_TYPE_ACTIVITY = "activity";
//     public static final String TARGET_TYPE_ACTIVITY_ALIAS = "activity-alias";
//     public static final String TARGET_TYPE_SERVICE = "service";
// }
// 
// Path: apt/src/main/java/link/anyauto/smartkey/apt/manifestanalyzer/TargetDescriptor.java
// public class TargetDescriptor {
//     public String name;
//     public String aliasName;
//     public ArrayList<TargetFilter> filters = new ArrayList<>();
// 
//     public String getSimpleName() {
//         return name.substring(name.lastIndexOf('.') + 1);
//     }
// }
// 
// Path: apt/src/main/java/link/anyauto/smartkey/apt/manifestanalyzer/TargetFilter.java
// public class TargetFilter {
//     public ArrayList<String> categories = new ArrayList<>();
//     public ArrayList<String> actions = new ArrayList<>();
// }


// Path: apt/src/main/java/link/anyauto/smartkey/apt/ActivityHandler.java
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.util.ArrayList;
import java.util.HashMap;
import javax.lang.model.element.Modifier;
import link.anyauto.smartkey.annotation.AnnotationConstants;
import link.anyauto.smartkey.annotation.SmartTarget;
import link.anyauto.smartkey.apt.manifestanalyzer.TargetDescriptor;
import link.anyauto.smartkey.apt.manifestanalyzer.TargetFilter;

    }

    public void addType(TargetDescriptor des) {
        TypeSpec.Builder type = types.get(des.name);
        if (type == null) {
            ClassName activityType = ClassName.bestGuess(des.name);
            ClassName builderName = ClassName.bestGuess(des.name + AnnotationConstants.SUFFIX_ACTIVITY_TARGET);
            addType(des.getSimpleName(), des.name, activityType, builderName, null);
        }
        if (des.filters.isEmpty() || des.filters.get(0).actions.isEmpty()) {
            return;
        }
        for (TargetFilter filter : des.filters) {
            for(String action : filter.actions) {
                if("android.intent.action.MAIN".equals(action))
                    continue;
                addGoActivityMethod(des.name,
                        "goWithAction_" + action.replace('.', '_').replace(" ", "").toUpperCase(),
                        action, filter.categories);
                addGoActivityMethod(des.name,
                        "goForResultWithAction_" + action.replace('.', '_').replace(" ", "").toUpperCase(),
                        action, filter.categories);
            }
        }
    }

    public void addAliasType(TargetDescriptor target) {
        if (target.filters.isEmpty() || target.filters.get(0).actions.isEmpty()) {
            return;
        }
        for (TargetFilter filter : target.filters) {