'use strict';

var apiService = require('../apiService').getInstance();

function FinishOrderResponse() {
}

FinishOrderResponse.prototype = {
    getResponse: function (productId, intervalId, userId) {
        var product = apiService.getProduct(productId);
        var order = apiService.registerOrder(productId, intervalId, userId);
        console.log("Saved order: ", JSON.stringify(product));
        var response = {
            attachment: {
                type: "template",
                payload: {
                    template_type: "receipt",
                    recipient_name: userId.toString(),
                    order_number: order.orderId.toString(),
                    currency: "USD",
                    payment_method: "Visa 2345",
                    order_url: "http://petersapparel.parseapp.com/order?order_id=123456",
                    timestamp: new Date().getTime(),
                    elements: [
                        {
                            "title": product.name,
                            "subtitle": product.description,
                            "quantity": 1,
                            "price": product.base_price == undefined ? 0.00 : parseFloat(product.base_price),
                            "currency": "RON",
                            "image_url": product.image
                        }
                    ],
                    summary: {
                        subtotal: parseFloat(product.base_price),
                        shipping_cost: 0.00,
                        total_tax: parseFloat(product.base_price) - parseFloat(product.base_price / 1.24),
                        total_cost: parseFloat(product.base_price)
                    },
                }
            }
        };

        return JSON.stringify(response);
    }
};

/**
 * @returns {FinishOrderResponse}
 */
module.exports.getInstance = function () {
    return new FinishOrderResponse();
};

@@ -64,16 +64,79 @@
 tance();
+%0Avar facebookApi = require('../facebookService').getInstance();
 %0A%0Afuncti
@@ -471,1354 +471,160 @@
 var 
-response = %7B%0A            attachment: %7B%0A                type: %22template%22,%0A                payload: %7B%0A                    template_type: %22receipt%22,%0A                    recipient_name: userId.toString(),%0A                    order_number: order.orderId.toString(),%0A                    currency: %22USD%22,%0A                    payment_method: %22Visa 2345%22,%0A                    order_url: %22http://petersapparel.parseapp.com/order?order_id=123456%22,%0A                    timestamp: new Date().getTime(),%0A                    elements: %5B%0A                        %7B%0A                            %22title%22: product.name,%0A                            %22subtitle%22: product.description,%0A                            %22quantity%22: 1,%0A                            %22price%22: product.base_price == undefined ? 0.00 : parseFloat(product.base_price),%0A                            %22currency%22: %22RON%22,%0A                            %22image_url%22: product.image%0A                        %7D%0A                    %5D,%0A                    summary: %7B%0A                        subtotal: parseFloat(product.base_price),%0A                        shipping_cost: 0.00,%0A                        total_tax: parseFloat(product.base_price) - parseFloat(product.base_price / 1.24),%0A                        total_cost: parseFloat(product.base_price)%0A                    %7D,%0A                %7D%0A            %7D%0A        %7D;%0A
+msg = %22Your order #%22+ order.orderId +%22 was received. We are waiting for yout between selected hours!%22;%0A        facebookApi.sendTextMessage(userId, msg);
 %0A   
@@ -654,16 +654,10 @@
 ify(
-response
+%7B%7D
 );%0A 

add notifier