// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/models/send/Button.java
// public class Button {
//     private enum Type {
//         @SerializedName("postback")
//         Postback,
//         @SerializedName("web_url")
//         WebUrl
//     }
//     private final Type type;
//     private final String title;
//     private final Action payload;
//     private final String url;
//     private final boolean messenger_extensions;
// 
//     private Button(Type type, String title, String url, Action action){
//         this.type = type;
//         this.title = title;
//         this.url = url;
//         this.payload = action;
//         this.messenger_extensions = false;
//     }
//     
//     private Button(Type type, String title, String url, boolean messenger_extensions){
//         this.type = type;
//         this.title = title;
//         this.url = url;
//         this.payload = null;
//         this.messenger_extensions = messenger_extensions;
//     }
// 
//     public static Button Url(String title, String url){
//         return new Button(Type.WebUrl, title, url, null);
//     }
// 
//     public static Button Postback(String title, Action action){
//         return new Button(Type.Postback, title, null, action);
//     }
//     
//     public static Button Url(String title, String url, boolean messenger_extensions){
//         return new Button(Type.WebUrl, title, url, messenger_extensions);
//     }
// }
// 
// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/models/send/Message.java
// public class Message {
// 
//     private transient final OkHttpClient HTTP_CLIENT;
//     private transient final Gson GSON;
// 
//     {
//         HTTP_CLIENT = new OkHttpClient();
//         GSON = new Gson();
//     }
// 
//     final private Attachment attachment;
//     final private String text;
//     
//     // add by kyawswar
//     @SerializedName("quick_replies")
//     final private List<QuickReply> quickReplies;
//     
//     private Message(Attachment attachment, String text) {
//         this.attachment = attachment;
//         this.text = text;
//         this.quickReplies = null;
//     }
// 
//     private Message(String text, QuickReply... quickReplies) {
//         this.attachment = null;
//         this.text = text;
//         this.quickReplies = Arrays.asList(quickReplies);
//     }
//     
//     public static Message Text(String text) {
//         return new Message(null, text);
//     }
//     
//     public static Message QuickReply(String text, QuickReply... quickReplies) {
//         return new Message(text, quickReplies);
//     }
//     
//     public static Message Image(String url) {
//         return new Message(Attachment.Image(url), null);
//     }
// 
//     public static Message Button(String text) {
//         return new Message(Attachment.Template(Payload.Button(text)), null);
//     }
// 
//     public static Message Generic() {
//         return new Message(Attachment.Template(Payload.Generic()), null);
//     }
// 
//     public boolean addQuickReply(QuickReply reply) {
//         return quickReplies.add(reply);
//     }
//     
//     public boolean addElement(Element element) {
//         return attachment.addElement(element);
//     }
// 
//     public boolean addButton(Button button) {
//         return attachment.addButton(button);
//     }
// 
//     public Response sendTo(String recipientId) throws IOException {
// 
//         RequestBody body = RequestBody.create(Main.JSON, GSON.toJson(new MessageWrapper(recipientId, this)));
//         Request request = new Request.Builder()
//                 .url(Main.END_POINT + "?access_token=" + sAccessToken)
//                 .header("Content-Type", "application/json; charset=UTF-8")
//                 .post(body)
//                 .build();
//         okhttp3.Response response = HTTP_CLIENT.newCall(request).execute();
//         final int code = response.code();
//         Response returnValue = null;
//         if (code == 200) {
//             System.out.println("WORK!");
//             returnValue = GSON.fromJson(response.body().string(), Response.class);
//         }else {
//             System.out.println("ERROR: " + response.body().string());
//         }
//         response.body().close();
//         return returnValue;
//     }
// 
//     class MessageWrapper {
//         private final Recipient recipient;
//         private final Message message;
//         MessageWrapper(String recipientId, Message message) {
//             this.recipient = new Recipient(recipientId);
//             this.message = message;
//         }
//     }
// }
// 
// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/models/webhook/ReceivedMessage.java
// public class ReceivedMessage {
//     public String object;
//     public List<Entry> entry;
// }


import com.google.gson.Gson;
import com.hyurumi.fb_bot_boilerplate.models.common.Action;
import com.hyurumi.fb_bot_boilerplate.models.send.Button;
import com.hyurumi.fb_bot_boilerplate.models.send.Element;
import com.hyurumi.fb_bot_boilerplate.models.send.Message;
import com.hyurumi.fb_bot_boilerplate.models.webhook.Messaging;
import com.hyurumi.fb_bot_boilerplate.models.webhook.ReceivedMessage;
import okhttp3.*;
import java.util.List;
import java.util.Random;
import static spark.Spark.get;
import static spark.Spark.post;
import static spark.SparkBase.port;
                            Message.Image("https://unsplash.it/764/400?image=200").sendTo(senderId);
                            break;
                        case 2:
                            sendSampleGenericMessage(senderId);
                            break;
                        default:
                            sendSamplePostBackMessage(senderId);
                            break;
                    }

                } else if (messaging.postback != null) {
                    // Receiving postback message
                    if (messaging.postback.payload == Action.ACTION_A) {
                        Message.Text("Action A").sendTo(senderId);
                    }else {
                        Message.Text("Action B").sendTo(senderId);
                    }
                } else if (messaging.delivery != null) {
                    // when the message is delivered, this webhook will be triggered.
                } else {
                    // sticker may not be supported for now.
                    System.out.println(request.body());
                }
            }
            System.out.println(request.body());
            return "";
        });
    }

    static private void sendSamplePostBackMessage(String senderId) throws Exception {
// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/models/send/Button.java
// public class Button {
//     private enum Type {
//         @SerializedName("postback")
//         Postback,
//         @SerializedName("web_url")
//         WebUrl
//     }
//     private final Type type;
//     private final String title;
//     private final Action payload;
//     private final String url;
//     private final boolean messenger_extensions;
// 
//     private Button(Type type, String title, String url, Action action){
//         this.type = type;
//         this.title = title;
//         this.url = url;
//         this.payload = action;
//         this.messenger_extensions = false;
//     }
//     
//     private Button(Type type, String title, String url, boolean messenger_extensions){
//         this.type = type;
//         this.title = title;
//         this.url = url;
//         this.payload = null;
//         this.messenger_extensions = messenger_extensions;
//     }
// 
//     public static Button Url(String title, String url){
//         return new Button(Type.WebUrl, title, url, null);
//     }
// 
//     public static Button Postback(String title, Action action){
//         return new Button(Type.Postback, title, null, action);
//     }
//     
//     public static Button Url(String title, String url, boolean messenger_extensions){
//         return new Button(Type.WebUrl, title, url, messenger_extensions);
//     }
// }
// 
// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/models/send/Message.java
// public class Message {
// 
//     private transient final OkHttpClient HTTP_CLIENT;
//     private transient final Gson GSON;
// 
//     {
//         HTTP_CLIENT = new OkHttpClient();
//         GSON = new Gson();
//     }
// 
//     final private Attachment attachment;
//     final private String text;
//     
//     // add by kyawswar
//     @SerializedName("quick_replies")
//     final private List<QuickReply> quickReplies;
//     
//     private Message(Attachment attachment, String text) {
//         this.attachment = attachment;
//         this.text = text;
//         this.quickReplies = null;
//     }
// 
//     private Message(String text, QuickReply... quickReplies) {
//         this.attachment = null;
//         this.text = text;
//         this.quickReplies = Arrays.asList(quickReplies);
//     }
//     
//     public static Message Text(String text) {
//         return new Message(null, text);
//     }
//     
//     public static Message QuickReply(String text, QuickReply... quickReplies) {
//         return new Message(text, quickReplies);
//     }
//     
//     public static Message Image(String url) {
//         return new Message(Attachment.Image(url), null);
//     }
// 
//     public static Message Button(String text) {
//         return new Message(Attachment.Template(Payload.Button(text)), null);
//     }
// 
//     public static Message Generic() {
//         return new Message(Attachment.Template(Payload.Generic()), null);
//     }
// 
//     public boolean addQuickReply(QuickReply reply) {
//         return quickReplies.add(reply);
//     }
//     
//     public boolean addElement(Element element) {
//         return attachment.addElement(element);
//     }
// 
//     public boolean addButton(Button button) {
//         return attachment.addButton(button);
//     }
// 
//     public Response sendTo(String recipientId) throws IOException {
// 
//         RequestBody body = RequestBody.create(Main.JSON, GSON.toJson(new MessageWrapper(recipientId, this)));
//         Request request = new Request.Builder()
//                 .url(Main.END_POINT + "?access_token=" + sAccessToken)
//                 .header("Content-Type", "application/json; charset=UTF-8")
//                 .post(body)
//                 .build();
//         okhttp3.Response response = HTTP_CLIENT.newCall(request).execute();
//         final int code = response.code();
//         Response returnValue = null;
//         if (code == 200) {
//             System.out.println("WORK!");
//             returnValue = GSON.fromJson(response.body().string(), Response.class);
//         }else {
//             System.out.println("ERROR: " + response.body().string());
//         }
//         response.body().close();
//         return returnValue;
//     }
// 
//     class MessageWrapper {
//         private final Recipient recipient;
//         private final Message message;
//         MessageWrapper(String recipientId, Message message) {
//             this.recipient = new Recipient(recipientId);
//             this.message = message;
//         }
//     }
// }
// 
// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/models/webhook/ReceivedMessage.java
// public class ReceivedMessage {
//     public String object;
//     public List<Entry> entry;
// }


// Path: src/main/java/com/hyurumi/fb_bot_boilerplate/Main.java
import com.google.gson.Gson;
import com.hyurumi.fb_bot_boilerplate.models.common.Action;
import com.hyurumi.fb_bot_boilerplate.models.send.Button;
import com.hyurumi.fb_bot_boilerplate.models.send.Element;
import com.hyurumi.fb_bot_boilerplate.models.send.Message;
import com.hyurumi.fb_bot_boilerplate.models.webhook.Messaging;
import com.hyurumi.fb_bot_boilerplate.models.webhook.ReceivedMessage;
import okhttp3.*;
import java.util.List;
import java.util.Random;
import static spark.Spark.get;
import static spark.Spark.post;
import static spark.SparkBase.port;

                            Message.Image("https://unsplash.it/764/400?image=200").sendTo(senderId);
                            break;
                        case 2:
                            sendSampleGenericMessage(senderId);
                            break;
                        default:
                            sendSamplePostBackMessage(senderId);
                            break;
                    }

                } else if (messaging.postback != null) {
                    // Receiving postback message
                    if (messaging.postback.payload == Action.ACTION_A) {
                        Message.Text("Action A").sendTo(senderId);
                    }else {
                        Message.Text("Action B").sendTo(senderId);
                    }
                } else if (messaging.delivery != null) {
                    // when the message is delivered, this webhook will be triggered.
                } else {
                    // sticker may not be supported for now.
                    System.out.println(request.body());
                }
            }
            System.out.println(request.body());
            return "";
        });
    }

    static private void sendSamplePostBackMessage(String senderId) throws Exception {
        Message message = Message.Button("This is a postback message; please choose the action below");