package com.ulisesbocchio.jasyptmavenplugin.mojo;

import com.ulisesbocchio.jasyptspringboot.properties.JasyptEncryptorConfigurationProperties;
import com.ulisesbocchio.jasyptspringboot.util.AsymmetricCryptography;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.util.function.Consumer;

@Mojo(name = "reencrypt", defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
public class ReencryptMojo extends AbstractReencryptMojo {
    @Parameter(property = "jasypt.plugin.old.password") private String oldPassword;
    @Parameter(property = "jasypt.plugin.old.private-key-string") private String oldPrivateKeyString;
    @Parameter(property = "jasypt.plugin.old.private-key-location") private String oldPrivateKeyLocation;
    @Parameter(property = "jasypt.plugin.old.private-key-format") private AsymmetricCryptography.KeyFormat oldPrivateKeyFormat;
    @Parameter(property = "jasypt.plugin.old.algorithm") private String oldAlgorithm;
    @Parameter(property = "jasypt.plugin.old.key-obtention-iterations") private String oldKeyObtentionIterations;
    @Parameter(property = "jasypt.plugin.old.pool-size") private String oldPoolSize;
    @Parameter(property = "jasypt.plugin.old.provider-name") private String oldProviderName;
    @Parameter(property = "jasypt.plugin.old.provider-class-name") private String oldProviderClassName;
    @Parameter(property = "jasypt.plugin.old.salt-generator-class-name") private String oldSaltGeneratorClassName;
    @Parameter(property = "jasypt.plugin.old.iv-generator-class-name") private String oldIvGeneratorClassName;
    @Parameter(property = "jasypt.plugin.old.string-output-type") private String oldStringOutputType;

    @Override
    protected void configure(JasyptEncryptorConfigurationProperties properties) {
        setIfNotNull(properties::setPassword, oldPassword);
        setIfNotNull(properties::setPrivateKeyString, oldPrivateKeyString);
        setIfNotNull(properties::setPrivateKeyLocation, oldPrivateKeyLocation);
        setIfNotNull(properties::setPrivateKeyFormat, oldPrivateKeyFormat);

        setIfNotNull(properties::setAlgorithm, oldAlgorithm);
        setIfNotNull(properties::setKeyObtentionIterations, oldKeyObtentionIterations);
        setIfNotNull(properties::setPoolSize, oldPoolSize);
        setIfNotNull(properties::setProviderName, oldProviderName);
        setIfNotNull(properties::setProviderClassName, oldProviderClassName);
        setIfNotNull(properties::setSaltGeneratorClassname, oldSaltGeneratorClassName);
        setIfNotNull(properties::setIvGeneratorClassname, oldIvGeneratorClassName);
        setIfNotNull(properties::setStringOutputType, oldStringOutputType);
    }
}

@@ -378,45 +378,8 @@
 r;%0A%0A
-import java.util.function.Consumer;%0A%0A
 @Moj
@@ -1467,33 +1467,32 @@
 -generator-class
--
 name%22) private S
@@ -1510,33 +1510,33 @@
 ltGeneratorClass
-N
+n
 ame;%0A    @Parame
@@ -1583,25 +1583,24 @@
 erator-class
--
 name%22) priva
@@ -1624,25 +1624,25 @@
 neratorClass
-N
+n
 ame;%0A    @Pa
@@ -2555,33 +2555,33 @@
 ltGeneratorClass
-N
+n
 ame);%0A        se
@@ -2643,25 +2643,25 @@
 neratorClass
-N
+n
 ame);%0A      

Fix property names.