package io.quarkus.hibernate.envers.deployment;

import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.hibernate.envers.HibernateEnversBuildTimeConfig;
import io.quarkus.hibernate.envers.HibernateEnversRecorder;

public final class HibernateEnversProcessor {

    @BuildStep
    FeatureBuildItem feature() {
        return new FeatureBuildItem(Feature.HIBERNATE_ENVERS);
    }

    @BuildStep
    public void registerEnversReflections(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, "org.hibernate.envers.DefaultRevisionEntity"));
        reflectiveClass
                .produce(new ReflectiveClassBuildItem(false, false, "org.hibernate.tuple.entity.DynamicMapEntityTuplizer"));
        reflectiveClass.produce(
                new ReflectiveClassBuildItem(false, false, "org.hibernate.tuple.component.DynamicMapComponentTuplizer"));
    }

    @BuildStep
    @Record(ExecutionTime.STATIC_INIT)
    public void applyConfig(HibernateEnversRecorder recorder,
            HibernateEnversBuildTimeConfig buildTimeConfig) {
        recorder.registerHibernateEnversIntegration(buildTimeConfig);
    }
}

@@ -42,16 +42,65 @@
 yment;%0A%0A
+import java.util.Arrays;%0Aimport java.util.List;%0A%0A
 import i
@@ -129,16 +129,16 @@
 eature;%0A
-
 import i
@@ -602,16 +602,88 @@
 ecorder;
+%0Aimport io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem;
 %0A%0Apublic
@@ -767,24 +767,24 @@
 feature() %7B%0A
-
         retu
@@ -833,32 +833,368 @@
 ENVERS);%0A    %7D%0A%0A
+    @BuildStep%0A    List%3CAdditionalJpaModelBuildItem%3E addJpaModelClasses() %7B%0A        return Arrays.asList(%0A                new AdditionalJpaModelBuildItem(org.hibernate.envers.DefaultRevisionEntity.class),%0A                new AdditionalJpaModelBuildItem(org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity.class));%0A    %7D%0A%0A
     @BuildStep%0A 

Add Envers entity base classes as JPA model classes