/*
 * Copyright 2015 devbury LLC
 *
 *    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 devbury.dewey.hipchat;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Component
@ConfigurationProperties(prefix = "hipchat")
public class HipChatSettings {

    @NotNull
    private String email;

    @NotNull
    private String password;

    @NotNull
    private String apiToken;

    private String xmppJid;
    private String name;
    private String mentionName;
    private String resource = "DeweyServer";
    private String server = "chat.hipchat.com";
    private int port = 5222;
    private List<String> groupsToJoin = new ArrayList<>();

    @Override
    public String toString() {
        return "HipChatSettings{" +
                "email='" + email + '\'' +
                ", xmppJid='" + xmppJid + '\'' +
                ", name='" + name + '\'' +
                ", mentionName='" + mentionName + '\'' +
                ", resource='" + resource + '\'' +
                ", server='" + server + '\'' +
                ", port=" + port +
                '}';
    }

    public String getMentionName() {
        return mentionName;
    }

    public void setMentionName(String mentionName) {
        this.mentionName = mentionName;
    }

    public String getPassword() {
        return password;
    }

    public String getResource() {
        return resource;
    }

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

    public void setResource(String resource) {
        this.resource = resource;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public int getPort() {
        return port;
    }

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

    public String getApiToken() {
        return apiToken;
    }

    public void setApiToken(String apiToken) {
        this.apiToken = apiToken;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getXmppJid() {
        return xmppJid;
    }

    public void setXmppJid(String xmppJid) {
        this.xmppJid = xmppJid;
    }

    public List<String> getGroupsToJoin() {
        return groupsToJoin;
    }

    public void setGroupsToJoin(String groupsToJoin) {
        this.groupsToJoin = Arrays.asList(groupsToJoin.split(","))
                .stream()
                .map(String::trim)
                .collect(Collectors.toList());
    }
}

@@ -642,24 +642,81 @@
 y.hipchat;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.s
@@ -827,16 +827,56 @@
 mponent;
+%0Aimport org.springframework.util.Assert;
 %0A%0Aimport
@@ -886,38 +886,32 @@
 vax.
-valid
+annot
 ation.
-constraints.NotNull
+PostConstruct
 ;%0Aim
@@ -1109,32 +1109,109 @@
 ings %7B%0A%0A    
-@NotNull
+private static final Logger logger = LoggerFactory.getLogger(HipChatSettings.class);%0A
 %0A    private
@@ -1224,30 +1224,16 @@
 g email;
-%0A%0A    @NotNull
 %0A    pri
@@ -1257,22 +1257,8 @@
 ord;
-%0A%0A    @NotNull
 %0A   
@@ -1283,17 +1283,16 @@
 iToken;%0A
-%0A
     priv
@@ -1546,24 +1546,465 @@
 yList%3C%3E();%0A%0A
+    @PostConstruct%0A    public void checkProperties() %7B%0A        Assert.hasText(email, %22hipchat.email is not set!%22);%0A        Assert.hasText(password, %22hipchat.password is not set!%22);%0A        Assert.hasText(apiToken, %22hipchat.apiToken is not set!%22);%0A        if (!groupsToJoin.isEmpty()) %7B%0A            logger.info(%22%7B%7D%22, groupsToJoin.stream()%0A                    .collect(Collectors.joining(%22, %22, %22Only joining groups: %22, %22%22)));%0A        %7D%0A    %7D%0A%0A
     @Overrid

Move hipchat property settings to settings class.