// Path: libs/payment/src/main/java/com/africastalking/payment/recipient/Consumer.java
// public final class Consumer {
// 
//     /*
//      * Payment Reasons
//      */
//     public static final String REASON_SALARY = "SalaryPayment";
//     public static final String REASON_SALARY_WITH_CHARGE = "SalaryPaymentWithWithdrawalChargePaid";
//     public static final String REASON_BUSINESS = "BusinessPayment";
//     public static final String REASON_BUSINESS_WITH_CHARGE = "BusinessPaymentWithWithdrawalChargePaid";
//     public static final String REASON_PROMOTION = "PromotionPayment";
// 
//     public String name;
//     public String phoneNumber;
//     public String currencyCode;
//     public float amount;
//     public String providerChannel;
// 
//     public String reason;
//     public HashMap<String, String> metadata = new HashMap<>();
// 
//     /**
//      * Consumer-type payment recipient, used in B2C transactions
//      * @param name Consumer name
//      * @param phoneNumber Consumer phone number
//      * @param amount Amount to transact, along with the currency code. e.g. KES 345
//      * @param reason Purpose for the payment. e.g. {@link com.africastalking.payment.recipient.Consumer Consumer.REASON_SALARY}
//      */
//     public Consumer(String name, String phoneNumber, String amount, String reason) {
//         this.name = name;
//         this.phoneNumber = phoneNumber;
//         this.reason = reason;
// 
//         try {
//             String[] currenciedAmount = amount.trim().split(" ");
//             this.currencyCode = currenciedAmount[0];
//             this.amount = Float.parseFloat(currenciedAmount[1]);
//         } catch (Exception ex) {
//             throw new RuntimeException(ex);
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return new Gson().toJson(this);
//     }
// 
// }


import com.africastalking.*;
import com.africastalking.payment.recipient.Consumer;
import com.africastalking.voice.action.*;
import com.google.gson.Gson;
import java.io.IOException;
import java.net.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import spark.ModelAndView;
import spark.template.handlebars.HandlebarsTemplateEngine;
import static spark.Spark.exception;
import static spark.Spark.get;
import static spark.Spark.port;
import static spark.Spark.post;
import static spark.Spark.staticFiles;
        log(String.format("HTTP Server: %s:%d", host.getHostAddress(), HTTP_PORT));
        log("\n");

        HashMap<String, String> states = new HashMap<>();
        String baseUrl = "http://aksalj.ngrok.io";
        String songUrl = "https://upload.wikimedia.org/wikipedia/commons/transcoded/4/49/National_Anthem_of_Kenya.ogg/National_Anthem_of_Kenya.ogg.mp3";

        setupAfricastalking();

        port(HTTP_PORT);
        
        staticFiles.location("/public");
        exception(Exception.class, (e, req, res) -> e.printStackTrace()); // print all exceptions

        get("/", (req, res) -> {
            Map<String, Object> data = new HashMap<>();
            data.put("req", req.pathInfo());
            return render("index", data);
        });

        // Send SMS
        post("/auth/register/:phone", (req, res) -> sms.send("Welcome to Awesome Company", "AT2FA", new String[] {req.params("phone")}, false), gson::toJson);

        // Send Airtime
        post("/airtime/:phone", (req, res) -> airtime.send(req.params("phone"), req.queryParams("amount")), gson::toJson);

        // Mobile Checkout
        post("/mobile/checkout/:phone", (req, res) -> payment.mobileCheckout("TestProduct", req.params("phone"), req.queryParams("amount"), null), gson::toJson);

        // Mobile B2C
// Path: libs/payment/src/main/java/com/africastalking/payment/recipient/Consumer.java
// public final class Consumer {
// 
//     /*
//      * Payment Reasons
//      */
//     public static final String REASON_SALARY = "SalaryPayment";
//     public static final String REASON_SALARY_WITH_CHARGE = "SalaryPaymentWithWithdrawalChargePaid";
//     public static final String REASON_BUSINESS = "BusinessPayment";
//     public static final String REASON_BUSINESS_WITH_CHARGE = "BusinessPaymentWithWithdrawalChargePaid";
//     public static final String REASON_PROMOTION = "PromotionPayment";
// 
//     public String name;
//     public String phoneNumber;
//     public String currencyCode;
//     public float amount;
//     public String providerChannel;
// 
//     public String reason;
//     public HashMap<String, String> metadata = new HashMap<>();
// 
//     /**
//      * Consumer-type payment recipient, used in B2C transactions
//      * @param name Consumer name
//      * @param phoneNumber Consumer phone number
//      * @param amount Amount to transact, along with the currency code. e.g. KES 345
//      * @param reason Purpose for the payment. e.g. {@link com.africastalking.payment.recipient.Consumer Consumer.REASON_SALARY}
//      */
//     public Consumer(String name, String phoneNumber, String amount, String reason) {
//         this.name = name;
//         this.phoneNumber = phoneNumber;
//         this.reason = reason;
// 
//         try {
//             String[] currenciedAmount = amount.trim().split(" ");
//             this.currencyCode = currenciedAmount[0];
//             this.amount = Float.parseFloat(currenciedAmount[1]);
//         } catch (Exception ex) {
//             throw new RuntimeException(ex);
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return new Gson().toJson(this);
//     }
// 
// }


// Path: example/src/main/java/com/africastalking/example/App.java
import com.africastalking.*;
import com.africastalking.payment.recipient.Consumer;
import com.africastalking.voice.action.*;
import com.google.gson.Gson;
import java.io.IOException;
import java.net.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import spark.ModelAndView;
import spark.template.handlebars.HandlebarsTemplateEngine;
import static spark.Spark.exception;
import static spark.Spark.get;
import static spark.Spark.port;
import static spark.Spark.post;
import static spark.Spark.staticFiles;

        log(String.format("HTTP Server: %s:%d", host.getHostAddress(), HTTP_PORT));
        log("\n");

        HashMap<String, String> states = new HashMap<>();
        String baseUrl = "http://aksalj.ngrok.io";
        String songUrl = "https://upload.wikimedia.org/wikipedia/commons/transcoded/4/49/National_Anthem_of_Kenya.ogg/National_Anthem_of_Kenya.ogg.mp3";

        setupAfricastalking();

        port(HTTP_PORT);
        
        staticFiles.location("/public");
        exception(Exception.class, (e, req, res) -> e.printStackTrace()); // print all exceptions

        get("/", (req, res) -> {
            Map<String, Object> data = new HashMap<>();
            data.put("req", req.pathInfo());
            return render("index", data);
        });

        // Send SMS
        post("/auth/register/:phone", (req, res) -> sms.send("Welcome to Awesome Company", "AT2FA", new String[] {req.params("phone")}, false), gson::toJson);

        // Send Airtime
        post("/airtime/:phone", (req, res) -> airtime.send(req.params("phone"), req.queryParams("amount")), gson::toJson);

        // Mobile Checkout
        post("/mobile/checkout/:phone", (req, res) -> payment.mobileCheckout("TestProduct", req.params("phone"), req.queryParams("amount"), null), gson::toJson);

        // Mobile B2C
        post("/mobile/b2c/:phone", (req, res) -> payment.mobileB2C("TestProduct", Arrays.asList(new Consumer("Boby", req.params("phone"), req.queryParams("amount"), Consumer.REASON_SALARY))), gson::toJson);