package net.squanchy;

import android.app.Activity;
import android.app.Notification;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import net.squanchy.eventdetails.domain.view.ExperienceLevel;
import net.squanchy.notification.NotificationCreator;
import net.squanchy.notification.NotificationService;
import net.squanchy.notification.Notifier;
import net.squanchy.schedule.domain.view.Event;
import net.squanchy.speaker.domain.view.Speaker;
import net.squanchy.support.lang.Optional;

import org.joda.time.LocalDateTime;

@SuppressWarnings("checkstyle:magicnumber")
public class DebugActivity extends Activity {

    private NotificationCreator notificationCreator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_debug);

        Button buttonSingleNotification = (Button) findViewById(R.id.button_test_single_notification);
        buttonSingleNotification.setOnClickListener(view -> testSingleNotification());

        Button buttonMultipleNotifications = (Button) findViewById(R.id.button_test_multiple_notifications);
        buttonMultipleNotifications.setOnClickListener(view -> testMultipleNotifications());

        Button buttonService = (Button) findViewById(R.id.button_test_service);
        buttonService.setOnClickListener(view -> testService());

        notificationCreator = new NotificationCreator(this);
    }

    private void testSingleNotification() {
        createAndNotifyTalksCount(1);
    }

    private void testMultipleNotifications() {
        createAndNotifyTalksCount(3);
    }

    private void createAndNotifyTalksCount(int count) {
        List<Event> events = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            events.add(createTestEvent(i));
        }
        List<Notification> notifications = notificationCreator.createFrom(events);

        Notifier notifier = Notifier.from(this);
        notifier.showNotifications(notifications);
    }

    private Event createTestEvent(int id) {
        LocalDateTime start = new LocalDateTime().plusMinutes(5);
        LocalDateTime end = new LocalDateTime().plusMinutes(45);
        return Event.create(
                String.valueOf(id),
                id,
                "1",
                start,
                end,
                "A very interesting talk",
                "That room over there",
                Optional.of(ExperienceLevel.ADVANCED),
                createTalkSpeakers(),
                Event.Type.TALK,
                true
        );
    }

    private List<Speaker> createTalkSpeakers() {
        List<Speaker> speakers = new ArrayList<>(2);
        speakers.add(Speaker.create(
                "1",
                101L,
                "Ajeje Brazorf",
                "https://yt3.ggpht.com/-d35Rq8vqvmE/AAAAAAAAAAI/AAAAAAAAAAA/zy1VyiRTNec/s900-c-k-no-mo-rj-c0xffffff/photo.jpg"
                )
        );
        return speakers;
    }

    private void testService() {
        Intent serviceIntent = new Intent(this, NotificationService.class);
        startService(serviceIntent);
    }
}

@@ -375,24 +375,31 @@
 Notification
+sIntent
 Service;%0Aimp
@@ -482,24 +482,72 @@
 view.Event;%0A
+import net.squanchy.schedule.domain.view.Place;%0A
 import net.s
@@ -2542,30 +2542,21 @@
     
-%22That room over there%22
+createPlace()
 ,%0A  
@@ -2699,16 +2699,17 @@
     true
+,
 %0A       
@@ -2705,24 +2705,263 @@
 ue,%0A        
+        Optional.absent(),%0A                Optional.absent()%0A        );%0A    %7D%0A%0A    private Optional%3CPlace%3E createPlace() %7B%0A        Place place = Place.create(%221%22, %22That room over there%22, Optional.absent());%0A        return Optional.of(place
 );%0A    %7D%0A%0A  
@@ -3454,16 +3454,23 @@
 fication
+sIntent
 Service.

Update DebugActivity to use optional place