package example.armeria.server.annotated;

import static com.google.common.base.Preconditions.checkArgument;

import java.time.Duration;
import java.util.List;

import org.reactivestreams.Publisher;

import com.google.common.collect.ImmutableList;

import com.linecorp.armeria.common.logging.LogLevel;
import com.linecorp.armeria.common.sse.ServerSentEvent;
import com.linecorp.armeria.server.annotation.Get;
import com.linecorp.armeria.server.annotation.Param;
import com.linecorp.armeria.server.annotation.ProducesEventStream;
import com.linecorp.armeria.server.annotation.decorator.LoggingDecorator;

import reactor.core.publisher.Flux;

/**
 * Examples how to send {@link ServerSentEvent}s.
 *
 * @see <a href="https://line.github.io/armeria/server-sse.html">Serving Server-Sent Events</a>
 */
@LoggingDecorator(
        requestLogLevel = LogLevel.INFO,            // Log every request sent to this service at INFO level.
        successfulResponseLogLevel = LogLevel.INFO  // Log every response sent from this service at INFO level.
)
public class ServerSentEventsService {

    private static final List<String> DATA = ImmutableList.of("foo", "bar", "baz", "qux");

    @Get("/{count}")
    @ProducesEventStream
    public Publisher<ServerSentEvent> sseWithCount(@Param int count) {
        checkArgument(count <= DATA.size(),
                      "count: %s (expected: <= %s)", count, DATA.size());
        // Emit events for every 200 millisecond.
        return Flux.interval(Duration.ofMillis(200))
                   .take(count)
                   .zipWithIterable(DATA)
                   .map(source -> ServerSentEvent.ofData(source.getT2()));
    }
}

@@ -47,67 +47,27 @@
 ort 
-static com.google.common.base.Preconditions.checkArgument;%0A
+java.time.Duration;
 %0Aimp
@@ -71,37 +71,35 @@
 import java.
+u
 ti
-me.Duration
+l.Arrays
 ;%0Aimport jav
@@ -155,57 +155,8 @@
 r;%0A%0A
-import com.google.common.collect.ImmutableList;%0A%0A
 impo
@@ -1031,24 +1031,21 @@
 A = 
-Immutable
+Arrays.as
 List
-.of
 (%22fo
@@ -1200,30 +1200,19 @@
     
-checkArgument
+if 
 (count 
-%3C=
+%3E
  DAT
@@ -1219,17 +1219,19 @@
 A.size()
-,
+) %7B
 %0A       
@@ -1235,26 +1235,86 @@
         
-          
+throw new IllegalArgumentException(%0A                    String.format(
 %22count: 
@@ -1355,17 +1355,28 @@
 .size())
-;
+);%0A        %7D
 %0A       

Remove Guava code in examples (#1606)