package ch.viascom.hipchat.api;

import ch.viascom.hipchat.api.api.RoomsAPI;
import ch.viascom.hipchat.api.exception.APIException;
import ch.viascom.hipchat.api.models.Card;
import ch.viascom.hipchat.api.models.ReplyMessage;
import ch.viascom.hipchat.api.models.Topic;
import ch.viascom.hipchat.api.models.card.*;
import ch.viascom.hipchat.api.models.message.MessageColor;
import ch.viascom.hipchat.api.request.models.AddMember;
import ch.viascom.hipchat.api.request.models.GetAllParticipants;
import ch.viascom.hipchat.api.request.models.SendMessage;
import ch.viascom.hipchat.api.request.models.SendNotification;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Created by patrickboesch on 11.04.16.
 */
public class RoomAPITest {

    private static final Logger log = LogManager.getLogger(RoomAPITest.class);
    private static final String clientToken = "";
    private static final String integrationToken = "";

    private static int testBotUserId;

    //@Test
    public void sendRoomNotificationTest() throws APIException {
        HipChat hipChat = new HipChat(integrationToken);
        hipChat.roomsAPI().sendRoomNotification(new SendNotification("Test-Room", "Hello World", MessageColor.RED, true));
    }

    //@Test
    public void sendRoomMessageTest() throws APIException {
        HipChat hipChat = new HipChat(clientToken);
        hipChat.roomsAPI().sendRoomMessage(new SendMessage("Test-Room", "Hello World"));
    }

    //@Test
    public void replyToMessageTest() throws APIException {
        HipChat hipChat = new HipChat(clientToken);
        hipChat.roomsAPI().replyToMessage(new ReplyMessage("Test-Room", "Reply", "")); // Fill out last parameter with parentId
    }

    //@Test
    public void setTopicTest() throws APIException {
        HipChat hipChat = new HipChat(integrationToken);
        hipChat.roomsAPI().setTopic(new Topic("Test-Room", "New fancy topic for our test room"));
    }

    //@Test
    public void getAllParticipantsTest() throws APIException {
        HipChat hipChat = new HipChat(integrationToken);
        log.debug(hipChat.roomsAPI().getAllParticipants(new GetAllParticipants("Test-Room", 0, 100, true)));

    }

    //@Test
    public void addMemberTest() throws APIException {
        HipChat hipChat = new HipChat(clientToken);
        hipChat.roomsAPI().addMember(new AddMember(testBotUserId, "Private-Test-Room", null));
    }

    //@Test
    public void sendRoomNotificationCardTest() throws APIException {
        HipChat hipChat = new HipChat(integrationToken);
        RoomsAPI roomsAPI = hipChat.roomsAPI();

        SendNotification notification = new SendNotification();
        notification.setRoomId("Test-Room");
        notification.setMessage("Hi from (puzzle) HipChat-API v2");
        notification.setColor(MessageColor.RED);
        notification.setNotify(true);

        Card card = new Card();
        card.setTitle("API Card");

        CardIcon icon = new CardIcon();
        icon.setUrl("https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/22438/fire-1366382911.png");
        card.setIcon(icon);
        card.setStyle(CardStyle.APPLICATION);
        card.setUrl("http://github.com");
        card.setId("3985698273957");
        card.setFormat(CardFormat.COMPACT);

        CardAttribute cardAttribute = new CardAttribute();

        cardAttribute.setLabel("Version");

        CardAttributeValue cardAttributeValue = new CardAttributeValue();

        cardAttributeValue.setLabel("1.0");
        CardIcon icon2 = new CardIcon();
        icon2.setUrl("https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/22438/puzzle-1366382992.png");
        cardAttributeValue.setIcon(icon2);

        cardAttribute.setValue(cardAttributeValue);

        card.getAttributes().add(cardAttribute);

        CardActivity cardActivity = new CardActivity();

        cardActivity.setHtml("API test Card from hipchat-api");
        cardActivity.setIcon(icon);

        card.setActivity(cardActivity);

        notification.setCard(card);

        roomsAPI.sendRoomNotification(notification);
    }
}

@@ -167,16 +167,62 @@
 s.Card;%0A
+import ch.viascom.hipchat.api.models.Message;%0A
 import c
@@ -461,203 +461,53 @@
 els.
-AddMember;%0Aimport ch.viascom.hipchat.api.request.models.GetAllParticipants;%0Aimport ch.viascom.hipchat.api.request.models.SendMessage;%0Aimport ch.viascom.hipchat.api.request.models.SendNotification
+*;%0Aimport org.apache.logging.log4j.LogManager
 ;%0Aim
@@ -543,55 +543,40 @@
 .Log
-Mana
 ger;%0A
+%0A
 import 
-org.apache.logging.log4j.Logger
+java.util.ArrayList
 ;%0A%0A/
@@ -2305,32 +2305,287 @@
  null));%0A    %7D%0A%0A
+    //@Test%0A    public void viewRoomHistoryTest() throws APIException %7B%0A        HipChat hipChat = new HipChat(clientToken);%0A        ArrayList%3CMessage%3E messages = hipChat.roomsAPI().viewRoomHistory(new ViewRoomHistory(%22TestRoom%22,0,100)).getItems();%0A    %7D%0A%0A
     //@Test%0A    

Add Test for viewRoomHistory