// Path: src/main/java/com/fatico/winthing/common/BaseController.java
// public class BaseController {
// 
//     protected final String prefix;
// 
//     public BaseController(String prefix) {
//         Objects.requireNonNull(prefix);
//         prefix = prefix.replaceFirst("^/+", "");
//         if (!prefix.isEmpty() && !prefix.endsWith("/")) {
//             prefix += "/";
//         }
//         this.prefix = prefix;
//     }
// 
//     protected Message makeMessage(final String topic) {
//         return new Message(prefix + topic);
//     }
// 
//     protected Message makeMessage(final String topic, final JsonElement payload) {
//         return new Message(prefix + topic, payload);
//     }
// 
//     protected Message makeMessage(final String topic, final JsonElement payload,
//         final QualityOfService qos) {
//         return new Message(prefix + topic, payload, qos);
//     }
// 
//     protected Message makeMessage(final String topic, final JsonElement payload,
//         final QualityOfService qos, boolean retained) {
//         return new Message(prefix + topic, payload, qos, retained);
//     }
// 
// }
// 
// Path: src/main/java/com/fatico/winthing/messaging/Message.java
// public class Message {
// 
//     private static final JsonElement DEFAULT_PAYLOAD = null;
//     private static final QualityOfService DEFAULT_QOS = QualityOfService.AT_MOST_ONCE;
//     private static final boolean DEFAULT_RETAINMENT = false;
// 
//     private final String topic;
//     private final JsonElement payload;
//     private final QualityOfService qos;
//     private final boolean retained;
// 
//     public Message(final String topic) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = DEFAULT_PAYLOAD;
//         this.qos = DEFAULT_QOS;
//         this.retained = DEFAULT_RETAINMENT;
//     }
// 
//     public Message(final String topic, final JsonElement payload) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = payload;
//         this.qos = DEFAULT_QOS;
//         this.retained = DEFAULT_RETAINMENT;
//     }
// 
//     public Message(final String topic, final JsonElement payload, final QualityOfService qos) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = payload;
//         this.qos = Objects.requireNonNull(qos);
//         this.retained = DEFAULT_RETAINMENT;
//     }
// 
//     public Message(final String topic, final JsonElement payload, final QualityOfService qos,
//             boolean retained) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = payload;
//         this.qos = Objects.requireNonNull(qos);
//         this.retained = retained;
//     }
// 
//     public String getTopic() {
//         return topic;
//     }
// 
//     public Optional<JsonElement> getPayload() {
//         return Optional.ofNullable(payload);
//     }
// 
//     public QualityOfService getQualityOfService() {
//         return qos;
//     }
// 
//     public boolean isRetained() {
//         return retained;
//     }
// 
// }
// 
// Path: src/main/java/com/fatico/winthing/messaging/Registry.java
// public interface Registry extends RegistryConfigurator {
// 
//     Map<String, QualityOfService> getSubscriptions();
// 
//     Collection<Consumer<Message>> getConsumers(String topic);
// 
//     Queue<Message> getInitialMessages();
// 
//     Optional<Message> getWill();
// 
// }


import com.fatico.winthing.common.BaseController;
import com.fatico.winthing.messaging.Message;
import com.fatico.winthing.messaging.Registry;
import com.google.inject.Inject;
import java.util.NoSuchElementException;
import java.util.Objects;
package com.fatico.winthing.systems.desktop;


public class DesktopController extends BaseController {

    private final DesktopService desktopService;

    @Inject
    public DesktopController(final Registry registry, final DesktopService desktopService) {
        super("desktop");
        this.desktopService = Objects.requireNonNull(desktopService);
        registry.subscribe(prefix + "commands/close_active_window", this::closeActiveWindow);
        registry.subscribe(prefix + "commands/set_display_sleep", this::setDisplaySleep);
    }

    public void closeActiveWindow(final Message message) {
// Path: src/main/java/com/fatico/winthing/common/BaseController.java
// public class BaseController {
// 
//     protected final String prefix;
// 
//     public BaseController(String prefix) {
//         Objects.requireNonNull(prefix);
//         prefix = prefix.replaceFirst("^/+", "");
//         if (!prefix.isEmpty() && !prefix.endsWith("/")) {
//             prefix += "/";
//         }
//         this.prefix = prefix;
//     }
// 
//     protected Message makeMessage(final String topic) {
//         return new Message(prefix + topic);
//     }
// 
//     protected Message makeMessage(final String topic, final JsonElement payload) {
//         return new Message(prefix + topic, payload);
//     }
// 
//     protected Message makeMessage(final String topic, final JsonElement payload,
//         final QualityOfService qos) {
//         return new Message(prefix + topic, payload, qos);
//     }
// 
//     protected Message makeMessage(final String topic, final JsonElement payload,
//         final QualityOfService qos, boolean retained) {
//         return new Message(prefix + topic, payload, qos, retained);
//     }
// 
// }
// 
// Path: src/main/java/com/fatico/winthing/messaging/Message.java
// public class Message {
// 
//     private static final JsonElement DEFAULT_PAYLOAD = null;
//     private static final QualityOfService DEFAULT_QOS = QualityOfService.AT_MOST_ONCE;
//     private static final boolean DEFAULT_RETAINMENT = false;
// 
//     private final String topic;
//     private final JsonElement payload;
//     private final QualityOfService qos;
//     private final boolean retained;
// 
//     public Message(final String topic) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = DEFAULT_PAYLOAD;
//         this.qos = DEFAULT_QOS;
//         this.retained = DEFAULT_RETAINMENT;
//     }
// 
//     public Message(final String topic, final JsonElement payload) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = payload;
//         this.qos = DEFAULT_QOS;
//         this.retained = DEFAULT_RETAINMENT;
//     }
// 
//     public Message(final String topic, final JsonElement payload, final QualityOfService qos) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = payload;
//         this.qos = Objects.requireNonNull(qos);
//         this.retained = DEFAULT_RETAINMENT;
//     }
// 
//     public Message(final String topic, final JsonElement payload, final QualityOfService qos,
//             boolean retained) {
//         this.topic = Objects.requireNonNull(topic);
//         this.payload = payload;
//         this.qos = Objects.requireNonNull(qos);
//         this.retained = retained;
//     }
// 
//     public String getTopic() {
//         return topic;
//     }
// 
//     public Optional<JsonElement> getPayload() {
//         return Optional.ofNullable(payload);
//     }
// 
//     public QualityOfService getQualityOfService() {
//         return qos;
//     }
// 
//     public boolean isRetained() {
//         return retained;
//     }
// 
// }
// 
// Path: src/main/java/com/fatico/winthing/messaging/Registry.java
// public interface Registry extends RegistryConfigurator {
// 
//     Map<String, QualityOfService> getSubscriptions();
// 
//     Collection<Consumer<Message>> getConsumers(String topic);
// 
//     Queue<Message> getInitialMessages();
// 
//     Optional<Message> getWill();
// 
// }


// Path: src/main/java/com/fatico/winthing/systems/desktop/DesktopController.java
import com.fatico.winthing.common.BaseController;
import com.fatico.winthing.messaging.Message;
import com.fatico.winthing.messaging.Registry;
import com.google.inject.Inject;
import java.util.NoSuchElementException;
import java.util.Objects;

package com.fatico.winthing.systems.desktop;


public class DesktopController extends BaseController {

    private final DesktopService desktopService;

    @Inject
    public DesktopController(final Registry registry, final DesktopService desktopService) {
        super("desktop");
        this.desktopService = Objects.requireNonNull(desktopService);
        registry.subscribe(prefix + "commands/close_active_window", this::closeActiveWindow);
        registry.subscribe(prefix + "commands/set_display_sleep", this::setDisplaySleep);
    }

    public void closeActiveWindow(final Message message) {
        desktopService.getForegroundWindow().ifPresent(desktopService::closeWindow);