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> args = new LinkedHashMap<>();
        args.put("mods", mods);
        if (pillar.isPresent()) {
            args.put("pillar", pillar.get());
        }
        if (queue.isPresent()) {
            args.put("queue", queue.get());
        }
        return new LocalCall<>("state.apply", Optional.empty(), Optional.of(args),
                new TypeToken<Map<String, Object>>() { });
    }

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

}

@@ -819,16 +819,18 @@
 Object%3E 
+kw
 args = n
@@ -851,32 +851,34 @@
 ap%3C%3E();%0A        
+kw
 args.put(%22mods%22,
@@ -923,32 +923,34 @@
 ) %7B%0A            
+kw
 args.put(%22pillar
@@ -1022,16 +1022,18 @@
         
+kw
 args.put
@@ -1142,16 +1142,18 @@
 onal.of(
+kw
 args),%0A 

Rename args to kwargs