package io.muoncore.example.event.guide;

import io.muoncore.Muon;
import io.muoncore.MuonBuilder;
import io.muoncore.config.AutoConfiguration;
import io.muoncore.config.MuonConfigBuilder;
import io.muoncore.protocol.event.ClientEvent;
import io.muoncore.protocol.event.client.DefaultEventClient;
import io.muoncore.protocol.event.client.EventClient;

public class EmitEvent {

    public static void main(String[] args) {

        AutoConfiguration config = MuonConfigBuilder.withServiceIdentifier("client").build();

        Muon muon = MuonBuilder.withConfig(config).build();

        muon.getDiscovery().blockUntilReady();

        EventClient eventClient = new DefaultEventClient(muon);

        eventClient.event(new ClientEvent<>(
                "UserRegistered",
                "users",
                null,
                null,
                null,
                new UserRegisteredEvent(
                        "regsanders",
                        "Reginald",
                        "Sanders")
        ));

        eventClient.event(new ClientEvent<>(
                "UserRegistered",
                "users",
                null,
                null,
                null,
                new UserRegisteredEvent(
                        "derek",
                        "Derek",
                        "Blimby")
        ));

        eventClient.event(new ClientEvent<>(
                "UserDeleted",
                "users",
                null,
                null,
                null,
                new UserDeletedEvent("regsanders")
        ));

        System.out.println("User data updated");
        muon.shutdown();
    }

    static class UserRegisteredEvent {
        private String username;
        private String firstname;
        private String lastname;

        public UserRegisteredEvent(String username, String firstname, String lastname) {
            this.username = username;
            this.firstname = firstname;
            this.lastname = lastname;
        }

        public String getUsername() {
            return username;
        }

        public String getFirstname() {
            return firstname;
        }

        public String getLastname() {
            return lastname;
        }
    }

    static class UserDeletedEvent {
        private String username;

        public UserDeletedEvent(String username) {
            this.username = username;
        }

        public String getUsername() {
            return username;
        }
    }

}

@@ -716,43 +716,44 @@
 ent(
-new ClientEvent%3C%3E(%0A                
+%0A                ClientEvent.ofType(
 %22Use
@@ -756,33 +756,33 @@
 %22UserRegistered%22
-,
+)
 %0A               
@@ -786,99 +786,50 @@
     
-%22users%22,%0A                null,%0A                null,%0A                null,%0A                
+.stream(%22users%22)%0A                .payload(
 new 
@@ -953,33 +953,32 @@
   %22Sanders%22)
-%0A        
+).build(
 ));%0A%0A       
@@ -1000,43 +1000,44 @@
 ent(
-new ClientEvent%3C%3E(%0A                
+%0A                ClientEvent.ofType(
 %22Use
@@ -1048,17 +1048,17 @@
 istered%22
-,
+)
 %0A       
@@ -1070,99 +1070,50 @@
     
-%22users%22,%0A                null,%0A                null,%0A                null,%0A                
+.stream(%22users%22)%0A                .payload(
 new 
@@ -1232,25 +1232,24 @@
 Blimby%22)
-%0A        
+).build(
 ));%0A%0A   
@@ -1275,57 +1275,61 @@
 ent(
-new ClientEvent%3C%3E(%0A                %22UserDeleted%22,
+%0A                ClientEvent.ofType(%22UserRegistered%22)
 %0A   
@@ -1345,38 +1345,32 @@
     
-%22users%22,%0A                null,
+        .stream(%22users%22)
 %0A   
@@ -1378,38 +1378,32 @@
             
-null,%0A
         
         null
@@ -1394,38 +1394,17 @@
     
-        null,%0A                
+.payload(
 new 
@@ -1433,25 +1433,24 @@
 anders%22)
-%0A        
+).build(
 ));%0A%0A   

Update guide doc.