package com.suse.salt.netapi.calls.modules;

import com.suse.salt.netapi.calls.LocalCall;

import com.google.gson.reflect.TypeToken;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * salt.modules.state
 */
public class State {

    private State() { }

    public static LocalCall<Map<String, Object>> apply(List<String> mods) {
        return apply(mods, Optional.empty(), Optional.empty());
    }

    public static LocalCall<Map<String, Object>> apply(String... mods) {
        return apply(Arrays.asList(mods), Optional.empty(), Optional.empty());
    }

    public static LocalCall<Map<String, Object>> apply(List<String> mods,
            Optional<Map<String, Object>> pillar, Optional<Boolean> queue) {
        Map<String, Object> kwargs = new LinkedHashMap<>();
        kwargs.put("mods", mods);
        if (pillar.isPresent()) {
            kwargs.put("pillar", pillar.get());
        }
        if (queue.isPresent()) {
            kwargs.put("queue", queue.get());
        }
        return new LocalCall<>("state.apply", Optional.empty(), Optional.of(kwargs),
                new TypeToken<Map<String, Object>>() { });
    }

    public static LocalCall<Object> showHighstate() {
        return new LocalCall<>("state.show_highstate", Optional.empty(), Optional.empty(),
                new TypeToken<Object>() { });
    }

}

@@ -897,20 +897,16 @@
     
-if (
 pillar.i
 sPre
@@ -901,25 +901,25 @@
 pillar.i
-s
+f
 Present(
 )) %7B%0A   
@@ -910,32 +910,20 @@
 Present(
-)) %7B%0A           
+p -%3E
  kwargs.
@@ -941,18 +941,8 @@
 %22, p
-illar.get(
 ));%0A
@@ -953,38 +953,24 @@
     
-%7D%0A        if (
 queue.i
-s
+f
 Present(
 )) %7B
@@ -969,24 +969,12 @@
 ent(
-)) %7B%0A           
+q -%3E
  kwa
@@ -995,30 +995,11 @@
 %22, q
-ueue.get());%0A        %7D
+));
 %0A   

Use ifPresent() to avoid calling get()