package com.speedment.common.codegen.internal.java.view.value;

import com.speedment.common.codegen.Generator;
import com.speedment.common.codegen.Transform;
import com.speedment.common.codegen.model.value.InvocationValue;

import java.util.Optional;

import static com.speedment.common.codegen.util.Formatting.nl;
import static com.speedment.common.codegen.util.Formatting.tab;
import static java.util.stream.Collectors.joining;

/**
 * Transforms from an {@link InvocationValue} to java code.
 *
 * @author Emil Forslund
 * @since  2.4.6
 */
public final class InvocationValueView
implements Transform<InvocationValue, String> {

    @Override
    public Optional<String> transform(Generator gen, InvocationValue model) {
        return Optional.of(
            (model.getType() == null ? "" :
                gen.on(model.getType()).get() + ".") +
            model.getValue() +
            (model.getValues().size() <= 3
                ? gen.onEach(model.getValues()).collect(joining(", ", "(", ")"))
                : gen.onEach(model.getValues()).collect(joining(
                    "," + nl() + tab(),
                    "(" + nl() + tab(),
                    nl() + ")"
                ))
            )
        );
    }
}

@@ -304,18 +304,22 @@
 matting.
-nl
+indent
 ;%0Aimport
@@ -371,19 +371,18 @@
 matting.
-tab
+nl
 ;%0Aimport
@@ -1020,16 +1020,37 @@
       : 
+(%22(%22 + nl() + indent(
 gen.onEa
@@ -1070,33 +1070,16 @@
 alues())
-.collect(joining(
 %0A       
@@ -1095,87 +1095,40 @@
     
-%22,%22 + nl() + tab(),%0A                    %22(%22 + nl() + tab(),%0A                   
+.collect(joining(%22,%22 + nl()))) +
  nl(
@@ -1152,17 +1152,16 @@
        )
-)
 %0A       

Fix minor formatting issues with new views