/*
 *
 * Copyright (c) 2006-2019, Speedment, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); You may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.speedment.plugins.enums;

import com.speedment.common.injector.InjectBundle;
import com.speedment.common.injector.Injector;
import com.speedment.common.injector.annotation.ExecuteBefore;
import com.speedment.common.injector.annotation.InjectKey;
import com.speedment.common.injector.annotation.WithState;
import com.speedment.generator.standard.StandardTranslatorKey;
import com.speedment.generator.translator.component.CodeGenerationComponent;
import com.speedment.generator.translator.component.TypeMapperComponent;
import com.speedment.generator.translator.internal.component.CodeGenerationComponentImpl;
import com.speedment.generator.translator.internal.component.TypeMapperComponentImpl;
import com.speedment.plugins.enums.internal.GeneratedEntityDecorator;
import com.speedment.plugins.enums.internal.ui.CommaSeparatedStringEditor;
import com.speedment.runtime.config.Table;
import com.speedment.runtime.config.trait.HasEnumConstantsUtil;
import com.speedment.tool.config.trait.HasEnumConstantsProperty;
import com.speedment.tool.propertyeditor.component.PropertyEditorComponent;
import com.speedment.tool.propertyeditor.internal.component.PropertyEditorComponentImpl;

import static com.speedment.common.injector.State.INITIALIZED;
import static com.speedment.common.injector.State.RESOLVED;

/**
 * A plugin for generating internal enums for columns marked as ENUM in the
 * database.
 * <p>
 * To use this plugin, add the following to your configuration tag in the
 * pom-file:
 * {@code <component>com.speedment.plugins.enums.EnumGeneratorComponent</component>}
 *
 * @author Emil Forslund
 * @author Simon Jonasson
 * @since  3.0.0
 */
@InjectKey(EnumGeneratorComponent.class)
public final class EnumGeneratorComponent {

    static InjectBundle include() {
        return InjectBundle.of(
            TypeMapperComponentImpl.class, 
            CodeGenerationComponentImpl.class, 
            PropertyEditorComponentImpl.class
        );
    }

    @ExecuteBefore(RESOLVED)
    void installDecorators(Injector injector,
            @WithState(INITIALIZED) TypeMapperComponent typeMappers,
            @WithState(INITIALIZED) CodeGenerationComponent codeGen,
            @WithState(RESOLVED) PropertyEditorComponent editors) {

        typeMappers.install(String.class, StringToEnumTypeMapper::new);
        typeMappers.install(Integer.class, IntegerToEnumTypeMapper::new);

        codeGen.add(
            Table.class,
            StandardTranslatorKey.GENERATED_ENTITY,
            new GeneratedEntityDecorator(injector)
        );

        editors.install(
            HasEnumConstantsProperty.class,
            HasEnumConstantsUtil.ENUM_CONSTANTS,
            CommaSeparatedStringEditor::new
        );
    }
}
@@ -661,16 +661,140 @@
 enums;%0A%0A
+import static com.speedment.common.injector.State.INITIALIZED;%0Aimport static com.speedment.common.injector.State.RESOLVED;%0A%0A
 import c
@@ -832,24 +832,24 @@
 jectBundle;%0A
-
 import com.s
@@ -1319,35 +1319,33 @@
 nslator.
-internal.component.
+provider.Standard
 CodeGene
@@ -1351,36 +1351,32 @@
 erationComponent
-Impl
 ;%0Aimport com.spe
@@ -1403,35 +1403,33 @@
 nslator.
-internal.component.
+provider.Standard
 TypeMapp
@@ -1439,20 +1439,16 @@
 omponent
-Impl
 ;%0Aimport
@@ -1928,132 +1928,8 @@
 l;%0A%0A
-import static com.speedment.common.injector.State.INITIALIZED;%0Aimport static com.speedment.common.injector.State.RESOLVED;%0A%0A
 /**%0A
@@ -2437,16 +2437,24 @@
         
+Standard
 TypeMapp
@@ -2460,36 +2460,31 @@
 perComponent
-Impl
 .class,
- 
 %0A           
@@ -2484,16 +2484,24 @@
         
+Standard
 CodeGene
@@ -2519,20 +2519,15 @@
 nent
-Impl
 .class,
- 
 %0A   
@@ -3356,9 +3356,10 @@
 ;%0A    %7D%0A
-
 %7D
+%0A

remove translator internal references