package lv.emes.libraries.tools.logging;

import lv.emes.libraries.communication.MS_TakenPorts;

/**
 * Properties for Remote logging server.
 * Those include hostname and port number to make HTTP requests.
 * Also default and configurable values are provided for endpoint names, which are part of full path to make HTTP requests
 * to put new events into repository and retrieve existing ones from it.
 * If event logging server is configured properly, that is enough to set host property value <b>host</b>.
 * <p>Setters and getters:
 * <ul>
 * <li>getHost</li>
 * <li>getPort</li>
 * <li>getEndpointRootName</li>
 * <li>getEndpointLogEvent</li>
 * <li>getEndpointGetSingleEvent</li>
 * <li>getEndpointGetAllEvents</li>
 * <li>getEndpointClearAllEvents</li>
 * <li>getSecret</li>
 * <li>withHost</li>
 * <li>withPort</li>
 * <li>withEndpointRootName</li>
 * <li>withEndpointLogEvent</li>
 * <li>withEndpointGetSingleEvent</li>
 * <li>withEndpointGetAllEvents</li>
 * <li>withEndpointClearAllEvents</li>
 * <li>withSecret</li>
 * </ul>
 *
 * @author eMeS
 * @version 1.0.
 */
public class LoggingRemoteServerProperties {

    /**
     * Secret key to be used in order to encrypt secret coming altogether with logging event to authorize logging.
     */
    public static final String SECRET_TO_ENCRYPT_SECRET = "Default remote logger secret 2018";

    private String host;
    private int port = MS_TakenPorts._REMOTE_LOGGING_SERVER_PORT;
    private String secret = SECRET_TO_ENCRYPT_SECRET;
    private String endpointRootName = "RemoteLogger";
    private String endpointStatus = "status";
    private String endpointLogEvent = "event";
    private String endpointGetAllEvents = "all";
    private String endpointClearAllEvents = "clear";

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public String getEndpointRootName() {
        return endpointRootName;
    }

    public String getEndpointLogEvent() {
        return endpointLogEvent;
    }

    public String getEndpointGetAllEvents() {
        return endpointGetAllEvents;
    }

    public String getEndpointClearAllEvents() {
        return endpointClearAllEvents;
    }

    public String getEndpointStatus() {
        return endpointStatus;
    }

    public String getSecret() {
        return secret;
    }

    /**
     * Sets host name of server.
     *
     * @param host host name.
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withHost(String host) {
        this.host = host;
        return this;
    }

    /**
     * Sets port number of server.
     *
     * @param port port number. <b>DEFAULT</b>: {@link MS_TakenPorts#_REMOTE_LOGGING_SERVER_PORT}
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withPort(int port) {
        this.port = port;
        return this;
    }

    /**
     * Sets root name for HTTP requests to endpoints.
     *
     * @param endpointRootName name of all endpoint path root (X) [GET X/productOwner/productName/...].
     *                         <p><b>DEFAULT</b>: "RemoteLogger"
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withEndpointRootName(String endpointRootName) {
        if (endpointGetAllEvents != null && !endpointGetAllEvents.equals(""))
            this.endpointRootName = endpointRootName;
        return this;
    }

    /**
     * Sets root name for HTTP requests to endpoints.
     *
     * @param status name of endpoint to get status of server (X) [GET endpointRootName/X].
     *               <p><b>DEFAULT</b>: "status"
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withEndpointStatus(String status) {
        if (endpointGetAllEvents != null && !endpointGetAllEvents.equals(""))
            this.endpointStatus = status;
        return this;
    }

    /**
     * Sets endpoint name to log new event to repository.
     *
     * @param endpointPutEvent name of endpoint (X) [PUT endpointRootName/productOwner/productName/X].
     *                         <p><b>DEFAULT</b>: "event"
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withEndpointLogEvent(String endpointPutEvent) {
        if (endpointGetAllEvents != null && !endpointGetAllEvents.equals(""))
            this.endpointLogEvent = endpointPutEvent;
        return this;
    }

    /**
     * Sets endpoint name to get all existing events in repository.
     *
     * @param endpointGetAllEvents name of endpoint (X) [GET endpointRootName/productOwner/productName/X].
     *                             <p><b>DEFAULT</b>: "all"
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withEndpointGetAllEvents(String endpointGetAllEvents) {
        if (endpointGetAllEvents != null && !endpointGetAllEvents.equals(""))
            this.endpointGetAllEvents = endpointGetAllEvents;
        return this;
    }

    /**
     * Sets endpoint name to clear / delete all existing events in repository.
     *
     * @param endpointDeleteAllEvents name of endpoint (X) [DELETE endpointRootName/productOwner/productName/X].
     *                                <p><b>DEFAULT</b>: "clear"
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withEndpointClearAllEvents(String endpointDeleteAllEvents) {
        if (endpointDeleteAllEvents != null && !endpointDeleteAllEvents.equals(""))
            this.endpointClearAllEvents = endpointDeleteAllEvents;
        return this;
    }

    /**
     * Sets value of the secret that in combination with <b>productOwner</b> and <b>productName</b> gives
     * access to read and write events to repository.
     *
     * @param secret secret value that is saved to Remote server on very first request that is made for
     *               specific <b>productOwner</b> and <b>productName</b>.
     *               For further requests check is made against this <b>secret</b> value and in case of mismatch
     *               of the value that is provided and the one that is stored in Remote server's repository,
     *               authorization error (HTTP: 401) occurs.
     *               <p><b>DEFAULT</b>: "Default secret 123"
     * @return reference to properties.
     */
    public LoggingRemoteServerProperties withSecret(String secret) {
        if (secret != null && !secret.equals(""))
            this.secret = secret;
        return this;
    }
}

@@ -152,16 +152,31 @@
 include 
+logging server 
 hostname
@@ -215,16 +215,16 @@
 quests.%0A
-
  * Also 
@@ -515,16 +515,242 @@
 host%3C/b%3E
+ and %3Cb%3Esecret%3C/b%3E.%0A * In case eMeS logging server is good enough for storing logging information, even %3Cb%3Ehost%3C/b%3E property can be left%0A * out in order to use default one %3Ca href=%22http://emeslv.sytes.net%22%3Eemeslv.sytes.net%3C/a%3E
 .%0A * %3Cp%3E
@@ -1304,17 +1304,17 @@
 rsion 1.
-0
+1
 .%0A */%0Apu
@@ -1580,24 +1580,24 @@
 ret 2018%22;%0A%0A
-
     private 
@@ -1603,24 +1603,45 @@
  String host
+ = %22emeslv.sytes.net%22
 ;%0A    privat

Add default host (emeslv.sytes.net) for remote logger