package nl.sikken.bertrik;

import java.time.Duration;

/**
 * Configuration class.
 */
final class TtnHabBridgeConfig extends BaseConfig implements ITtnHabBridgeConfig {
    
    /**
     * One enumeration item per configuration item.
     */
    private enum EConfigItem {
        HABITAT_URL("habitat.url", "http://habitat.habhub.org", "URL of the habitat server"),
        HABITAT_TIMEOUT_MS("habitat.timeout", "3000", "Timeout in milliseconds"),

        TTN_MQTT_URL("ttn.mqtt.url", "tcp://eu.thethings.network", "URL of the TTN MQTT server"),
        TTN_APP_ID("ttn.app.id", "habhub", "TTN Application Id (e.g. habhub, ttnmapper, etc.)"),
        TTN_APP_KEY("ttn.app.key", "ttn-account-v2.Sh49WL90oQz-ZuxoDrS6yKuACL_jtAA0agdDfO_eVj4", "TTN Application key"),
        TTN_GW_CACHE_EXPIRY("ttn.gwcache.expiry", "600", "Gateway cache expiration time (seconds)"),
        TTN_PAYLOAD_ENCODING("ttn.payload.encoding", "cayenne",
                "Payload format, allowed values: 'sodaqone','json','cayenne'"),
        ;
        
        private final String key;
        private final String value;
        private final String comment;

        EConfigItem(String key, String def, String comment) {
            this.key = key;
            this.value = def;
            this.comment = comment;
        }
    }
    
    /**
     * Constructor.
     * 
     * Configures all settings to their default value.
     */
    public TtnHabBridgeConfig() {
        for (EConfigItem e : EConfigItem.values()) {
            add(e.key, e.value, e.comment);
        }
    }
    
    @Override
    public Duration getHabitatTimeout() {
        return Duration.ofMillis(Integer.parseInt(get(EConfigItem.HABITAT_TIMEOUT_MS.key)));
    }

    @Override
    public String getHabitatUrl() {
        return get(EConfigItem.HABITAT_URL.key);
    }

    @Override
    public String getTtnMqttUrl() {
        return get(EConfigItem.TTN_MQTT_URL.key);
    }

    @Override 
    public String getTtnAppId() {
        return get(EConfigItem.TTN_APP_ID.key);
    }
    
    @Override 
    public String getTtnAppKey() {
        return get(EConfigItem.TTN_APP_KEY.key);
    }

    @Override
    public int getTtnGwCacheExpiry() {
        return Integer.parseInt(get(EConfigItem.TTN_GW_CACHE_EXPIRY.key));
    }

    @Override
    public String getTtnPayloadEncoding() {
        return get(EConfigItem.TTN_PAYLOAD_ENCODING.key);
    }
    
}

@@ -427,9 +427,9 @@
 %22, %22
-3
+5
 000%22

Increase habitat timeout to 5 seconds.