package io.quarkus.liquibase.runtime;

import javax.sql.DataSource;

import io.quarkus.liquibase.LiquibaseFactory;

/**
 * The quarkus liquibase creator
 */
class LiquibaseCreator {
    /**
     * The liquibase runtime configuration
     */
    private final LiquibaseDataSourceRuntimeConfig liquibaseRuntimeConfig;
    /**
     * The liquibase build time configuration
     */
    private final LiquibaseDataSourceBuildTimeConfig liquibaseBuildTimeConfig;

    /**
     * The default constructor
     * 
     * @param liquibaseRuntimeConfig the liquibase runtime configuration
     * @param liquibaseBuildTimeConfig the liquibase build time configuration
     */
    public LiquibaseCreator(LiquibaseDataSourceRuntimeConfig liquibaseRuntimeConfig,
            LiquibaseDataSourceBuildTimeConfig liquibaseBuildTimeConfig) {
        this.liquibaseRuntimeConfig = liquibaseRuntimeConfig;
        this.liquibaseBuildTimeConfig = liquibaseBuildTimeConfig;
    }

    /**
     * Creates the quarkus liquibase instance
     * 
     * @param dataSource the liquibase datasource
     * @return the corresponding quarkus liquibase instance.
     */
    public LiquibaseFactory createLiquibase(DataSource dataSource) {
        LiquibaseConfig config = new LiquibaseConfig();
        config.changeLog = liquibaseBuildTimeConfig.changeLog;
        liquibaseRuntimeConfig.labels.ifPresent(c -> config.labels = c);
        liquibaseRuntimeConfig.contexts.ifPresent(c -> config.contexts = c);
        liquibaseRuntimeConfig.databaseChangeLogLockTableName.ifPresent(c -> config.databaseChangeLogLockTableName = c);
        liquibaseRuntimeConfig.databaseChangeLogTableName.ifPresent(c -> config.databaseChangeLogTableName = c);
        config.defaultSchemaName = liquibaseRuntimeConfig.defaultSchemaName;
        config.defaultCatalogName = liquibaseRuntimeConfig.defaultCatalogName;
        config.liquibaseTablespaceName = liquibaseRuntimeConfig.liquibaseTablespaceName;
        config.liquibaseSchemaName = liquibaseRuntimeConfig.liquibaseSchemaName;
        config.liquibaseCatalogName = liquibaseRuntimeConfig.liquibaseCatalogName;
        config.migrateAtStart = liquibaseRuntimeConfig.migrateAtStart;
        config.cleanAtStart = liquibaseRuntimeConfig.cleanAtStart;
        config.validateOnMigrate = liquibaseRuntimeConfig.validateOnMigrate;
        return new LiquibaseFactory(config, dataSource);
    }
}

@@ -1321,32 +1321,36 @@
 ngeLog;%0A        
+if (
 liquibaseRuntime
@@ -1364,25 +1364,25 @@
 labels.i
-f
+s
 Present(
 c -%3E con
@@ -1365,36 +1365,48 @@
 abels.isPresent(
-c -%3E
+)) %7B%0A           
  config.labels =
@@ -1402,36 +1402,83 @@
 ig.labels = 
-c);%0A        
+liquibaseRuntimeConfig.labels.get();%0A        %7D%0A        if (
 liquibaseRun
@@ -1498,25 +1498,25 @@
 ntexts.i
-f
+s
 Present(
 c -%3E con
@@ -1499,36 +1499,48 @@
 texts.isPresent(
-c -%3E
+)) %7B%0A           
  config.contexts
@@ -1542,28 +1542,77 @@
 texts = 
-c);%0A        
+liquibaseRuntimeConfig.contexts.get();%0A        %7D%0A        if (
 liquibas
@@ -1654,33 +1654,33 @@
 kTableName.i
-f
+s
 Present(
 c -%3E config.
@@ -1659,36 +1659,48 @@
 eName.isPresent(
-c -%3E
+)) %7B%0A           
  config.database
@@ -1724,28 +1724,99 @@
 eName = 
-c);%0A        
+liquibaseRuntimeConfig.databaseChangeLogLockTableName.get();%0A        %7D%0A        if (
 liquibas
@@ -1862,17 +1862,17 @@
 me.i
-f
+s
 Present(
 c -%3E
@@ -1871,12 +1871,24 @@
 ent(
-c -%3E
+)) %7B%0A           
  con
@@ -1924,11 +1924,74 @@
 e = 
-c);
+liquibaseRuntimeConfig.databaseChangeLogTableName.get();%0A        %7D
 %0A   

Remove lambdas from Liquibase runtime code