package com.melt.config;

import com.melt.config.constructor.ConstructorParameter;
import com.melt.config.property.BeanProperty;
import com.melt.core.BeansContainer;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

public class BeanInfo {
    private String name;
    private Class clazz;
    private Scope scope;
    private AutoWiredBy autoWiredBy;
    private List<ConstructorParameter> constructorParameters = newArrayList();
    private List<BeanProperty> properties = newArrayList();
    private boolean isInterfaceType = false;

    public BeanInfo(String name, Class clazz, Scope scope) {
        this.name = name;
        this.clazz = clazz;
        if (clazz.isInterface()) {
            isInterfaceType = true;
        }
        this.scope = scope;
        this.autoWiredBy = AutoWiredBy.NULL;
    }

    public BeanInfo(String name, Class clazz) {
        this(name, clazz, Scope.SINGLETON);
    }

    public void injectProperties(BeansContainer beansContainer) {
        for (BeanProperty beanProperty : getProperties()) {
            beanProperty.injectPropertyValue(beansContainer);
        }
    }

    public boolean isInterface() {
        return isInterfaceType;
    }

    public boolean isDefaultConstructorBean() {
        return constructorParameters.size() == 0;
    }

    public void addProperty(BeanProperty beanProperty) {
        this.properties.add(beanProperty);
    }

    public void addConstructorParameter(ConstructorParameter constructorParameter) {
        this.constructorParameters.add(constructorParameter);
    }

    public List<BeanProperty> getProperties() {
        return properties;
    }

    public String getName() {
        return name;
    }

    public Class getClazz() {
        return clazz;
    }

    public Scope getScope() {
        return scope;
    }

    public List<ConstructorParameter> getConstructorParameters() {
        return constructorParameters;
    }

    public AutoWiredBy getAutoWiredBy() {
        return autoWiredBy;
    }

    public void setAutoWiredBy(AutoWiredBy autoWiredBy) {
        this.autoWiredBy = autoWiredBy;
    }

    public void autoWiredProperties(BeansContainer beansContainer) {
        autoWiredBy.autoWired().autoWired(beansContainer, this);
    }
}

@@ -999,32 +999,77 @@
 ansContainer) %7B%0A
+        autoWiredProperties(beansContainer);%0A
         for (Bea
@@ -1183,32 +1183,173 @@
        %7D%0A    %7D%0A%0A
+    public void autoWiredProperties(BeansContainer beansContainer) %7B%0A        autoWiredBy.autoWired().autoWired(beansContainer, this);%0A    %7D%0A%0A
     public boole
@@ -2326,148 +2326,7 @@
    %7D
-%0A%0A    public void autoWiredProperties(BeansContainer beansContainer) %7B%0A        autoWiredBy.autoWired().autoWired(beansContainer, this);%0A    %7D
 %0A%7D%0A

move auto wire into inject property