/*
 * Copyright 2019-2020, EnMasse authors.
 * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
 */

package io.enmasse.iot.infinispan.config;

import com.google.common.base.MoreObjects;

// Align with ExternalInfinispanServer
public class InfinispanProperties {

    public static class CacheNames {
        private static final String DEFAULT_ADAPTER_CREDENTIALS_CACHE_NAME = "adapterCredentials";
        private static final String DEFAULT_DEVICE_CONNECTIONS_CACHE_NAME = "deviceStates";
        private static final String DEFAULT_DEVICES_CACHE_NAME = "devices";

        private String adapterCredentials = DEFAULT_ADAPTER_CREDENTIALS_CACHE_NAME;
        private String deviceConnections = DEFAULT_DEVICE_CONNECTIONS_CACHE_NAME;
        private String devices = DEFAULT_DEVICES_CACHE_NAME;

        public void setAdapterCredentials(String adapterCredentialsCacheName) {
            this.adapterCredentials = adapterCredentialsCacheName;
        }

        public String getAdapterCredentials() {
            return adapterCredentials;
        }

        public void setDeviceConnections(String deviceStatesCacheName) {
            this.deviceConnections = deviceStatesCacheName;
        }

        public String getDeviceConnections() {
            return deviceConnections;
        }

        public void setDevices(String devicesCacheName) {
            this.devices = devicesCacheName;
        }

        public String getDevices() {
            return devices;
        }

        @Override
        public String toString() {
             return MoreObjects.toStringHelper(this)
                     .add("adapterCredentials", this.adapterCredentials)
                     .add("devices", this.devices)
                     .add("deviceConnections", this.deviceConnections)
                     .toString();
        }

    }

    private static final boolean DEFAULT_TRY_CREATE = false;
    public static final boolean DEFAULT_UPLOAD_SCHEMA = true;
    private static final boolean DEFAULT_OVERRIDE_SCHEMA = true;
    private static final boolean DEFAULT_FAIL_ON_SCHEMA_MISMATCH = false;

    private static final String DEFAULT_HOST = "localhost";
    private static final int DEFAULT_PORT = 11222;
    private static final boolean DEFAULT_USE_TLS = false;

    private static final int DEFAULT_DELETION_CHUNK_SIZE = 0;

    private boolean tryCreate = DEFAULT_TRY_CREATE;

    private String host = DEFAULT_HOST;
    private int port = DEFAULT_PORT;

    private boolean useTls = DEFAULT_USE_TLS;

    private int deletionChunkSize = DEFAULT_DELETION_CHUNK_SIZE;

    /**
     * If {@code true}, then schema should be uploaded to the registry.
     */
    private boolean uploadSchema = DEFAULT_UPLOAD_SCHEMA;

    /**
     * If {@code true}, then schema should be overwritten when uploading to the registry.
     * <br>
     * <strong>Note:</strong> If the field {@link #uploadSchema} is set to {@code false}, then
     * this field has no effect.
     */
    private boolean overrideSchema = DEFAULT_OVERRIDE_SCHEMA;

    private boolean failOnSchemaMismatch = DEFAULT_FAIL_ON_SCHEMA_MISMATCH;

    private CacheNames cacheNames = new CacheNames();

    private String trustStorePath;

    private String username;
    private String password;
    private String saslRealm;
    private String saslServerName;

    public void setTryCreate(boolean tryCreate) {
        this.tryCreate = tryCreate;
    }

    public boolean isTryCreate() {
        return tryCreate;
    }

    public void setDeletionChunkSize(int deletionChunkSize) {
        this.deletionChunkSize = deletionChunkSize;
    }

    public int getDeletionChunkSize() {
        return deletionChunkSize;
    }

    public void setUploadSchema(boolean uploadSchema) {
        this.uploadSchema = uploadSchema;
    }

    public boolean isUploadSchema() {
        return uploadSchema;
    }

    public void setOverrideSchema(boolean overrideSchema) {
        this.overrideSchema = overrideSchema;
    }

    public boolean isOverrideSchema() {
        return overrideSchema;
    }

    public void setFailOnSchemaMismatch(boolean failOnSchemaMismatch) {
        this.failOnSchemaMismatch = failOnSchemaMismatch;
    }

    public boolean isFailOnSchemaMismatch() {
        return failOnSchemaMismatch;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getHost() {
        return host;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getPort() {
        return port;
    }

    public void setUseTls(boolean useTls) {
        this.useTls = useTls;
    }

    public boolean isUseTls() {
        return useTls;
    }

    public void setTrustStorePath(String trustStorePath) {
        this.trustStorePath = trustStorePath;
    }

    public String getTrustStorePath() {
        return trustStorePath;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

    public void setSaslRealm(String saslRealm) {
        this.saslRealm = saslRealm;
    }

    public String getSaslRealm() {
        return saslRealm;
    }

    public void setSaslServerName(String saslServerName) {
        this.saslServerName = saslServerName;
    }

    public String getSaslServerName() {
        return saslServerName;
    }

    public void setCacheNames(CacheNames cacheNames) {
        this.cacheNames = cacheNames;
    }

    public CacheNames getCacheNames() {
        return cacheNames;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("host", this.host)
                .add("port", this.port)
                .add("username", this.username)
                .add("useTls", this.useTls)
                .add("saslRealm", this.saslRealm)
                .add("saslServername", this.saslServerName)
                .add("trustStorePath", this.trustStorePath)
                .add("tryCreate", this.tryCreate)
                .add("uploadSchema", this.uploadSchema)
                .add("cacheNames", this.cacheNames)
                .toString();
    }
}

@@ -526,22 +526,27 @@
  %22device
-States
+-connection
 %22;%0A     

Fix default name of device connection cache (#4478)