/**
 * JBoss, Home of Professional Open Source.
 * Copyright 2014-2019 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.pnc.common.json.moduleconfig;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.jboss.pnc.common.json.AbstractModuleConfig;
import org.jboss.pnc.common.util.StringUtils;

import javax.ws.rs.DefaultValue;
import java.util.Map;

/**
 * Runtime configuration parameters for the Web UI.
 *
 * @author Alex Creasy
 */
@JsonIgnoreProperties({ "@module-config"})
public class UIModuleConfig extends AbstractModuleConfig {

    public static final String MODULE_NAME = "ui";

    private final String pncUrl;
    private final String pncRestUrl;
    private final String pncNotificationsUrl;
    private final String daUrl;
    private final String userGuideUrl;
    private final Integer ssoTokenLifespan;
    private final KeycloakConfig keycloak;
    private final Map<String, String> grafana;
    private final String bifrostUrl;

    public UIModuleConfig(
            @JsonProperty("pncUrl") String pncUrl,
            @JsonProperty("pncRestUrl") String pncRestUrl,
            @JsonProperty("pncNotificationsUrl") String pncNotificationsUrl,
            @JsonProperty("daUrl") String daUrl,
            @JsonProperty("userGuideUrl") String userGuideUrl,
            @JsonProperty("ssoTokenLifespan") String ssoTokenLifespan,
            @JsonProperty("keycloak") KeycloakConfig keycloak,
            @JsonProperty("grafana") @DefaultValue("{}") Map<String, String> grafana,
            @JsonProperty("bifrostUrl") String bifrostUrl) {
        this.pncUrl = pncUrl;
        this.pncRestUrl = pncRestUrl;
        this.pncNotificationsUrl = pncNotificationsUrl;
        this.daUrl = daUrl;
        this.userGuideUrl = userGuideUrl;
        this.ssoTokenLifespan = StringUtils.parseInt(ssoTokenLifespan, 86400000); //default to 24h
        this.keycloak = keycloak;
        this.grafana = grafana;
        this.bifrostUrl = bifrostUrl;
    }

    /**
     * @return String representation of the PNC REST API version 1 base URL
     */
    @JsonProperty("pncUrl")
    public String getPncUrl() {
        return pncUrl;
    }

    /**
     * @return String representation of the PNC REST API version 2+ base URL.
     */
    @JsonProperty("pncRestUrl")
    public String getPncRestUrl() {
        return pncRestUrl;
    }

    /**
     * @return String representation of the PNC notification WebSocket URL.
     */
    @JsonProperty("pncNotificationsUrl")
    public String getPncNotificationsUrl() {
        return pncNotificationsUrl;
    }

    /**
     * @return String representation of the Dependency Analyzer API base URL.
     */
    @JsonProperty("daUrl")
    public String getDaUrl() {
        return daUrl;
    }

    /**
     * @return String representation of the PNC user guide URL
     */
    public String getUserGuideUrl() {
        return userGuideUrl;
    }

    public Integer getSsoTokenLifespan() {
        return ssoTokenLifespan;
    }

    /**
     * @return Keycloak object of Web UI configuration parameters for the Keycloak JavaScript adapter.
     */
    @JsonProperty("keycloak")
    public KeycloakConfig getKeycloak() {
        return keycloak;
    }


    /**
     * @return A map of grafana URLs to widgets embedded in the UI Dashboard
     */
    @JsonProperty("grafana")
    public Map<String, String> getGrafana() {
        return grafana;
    }

    public String getBifrostUrl() {
        return bifrostUrl;
    }

    @Override
    public String toString() {
        return "UIModuleConfig{" +
                "pncUrl='" + pncUrl + '\'' +
                ", pncRestUrl='" + pncRestUrl + '\'' +
                ", pncNotificationsUrl='" + pncNotificationsUrl + '\'' +
                ", daUrl='" + daUrl + '\'' +
                ", userGuideUrl='" + userGuideUrl + '\'' +
                ", ssoTokenLifespan=" + ssoTokenLifespan +
                ", keycloak=" + keycloak +
                ", grafana=" + grafana +
                ", bifrostUrl=" + bifrostUrl +
                '}';
    }
}

@@ -1623,16 +1623,56 @@
 rostUrl;
+%0A    private final String kafkaStoreUrl;
 %0A%0A    pu
@@ -2268,16 +2268,81 @@
 frostUrl
+,%0A            @JsonProperty(%22kafkaStoreUrl%22) String kafkaStoreUrl
 ) %7B%0A    
@@ -2726,32 +2726,76 @@
 l = bifrostUrl;%0A
+        this.kafkaStoreUrl = kafkaStoreUrl;%0A
     %7D%0A%0A    /**%0A 
@@ -4290,24 +4290,100 @@
 Url;%0A    %7D%0A%0A
+    public String getKafkaStoreUrl() %7B%0A        return kafkaStoreUrl;%0A    %7D%0A%0A
     @Overrid
@@ -4870,16 +4870,16 @@
 afana +%0A
-
         
@@ -4917,16 +4917,69 @@
 stUrl +%0A
+                %22, kafkaStoreUrl=%22 + kafkaStoreUrl +%0A
         

Add kafka store url to UI config