import {Meteor} from "meteor/meteor";
import {sendSMS} from "/imports/api/Users/server/init/sms";

function printToConsole(to: string, body: string) {
    console.log("=================================");
    console.log("To:", to);
    console.log("Body:", body);
    console.log("=================================");
}

export class SMSNotifications {

    private static send(to: string, body: string) {
        if(Meteor.isDevelopment) {
            printToConsole(to, body);
        } else {
            sendSMS(to, body);
        }
    }

    static sendNewThreadNotification(toNumber: string, toName: string, senderName: string, threadId: string) {
        const threadUrl = Meteor.absoluteUrl() + "dashboard/messages/inbox/thread/" + threadId;
        const body = "Everyspace inbox message received!\n\n" +
            "Hi " + toName + ",\n\n" +
            "You have received a message from " + senderName + " on the Everyspace platform.\n\n" +
            "Access the message here - " + threadUrl + "\n\n" +
            "Thanks,\n" +
            "The Everyspace Crew";

        this.send(toNumber, body);
    }

    static sendUnreadCountInThreadNotification(toNumber: string, toName: string, unreadCount: number, senderName: string, threadId: string) {
        const threadUrl = Meteor.absoluteUrl() + "dashboard/messages/inbox/thread/" + threadId;
        const body = "Everyspace unread message!\n\n" +
            "Hi " + toName + ",\n\n" +
            "You have " + unreadCount + " unread " + (unreadCount === 1 ? "message":"messages") + " from " + senderName + " on the Everyspace platform.\n\n" +
            "Access the message thread here - " + threadUrl + "\n\n" +
            "Thanks,\n" +
            "The Everyspace Crew";

        this.send(toNumber, body);
    }

    static sendNewMessageNotification(toNumber: string, toName: string, senderName: string, threadId: string) {
        const threadUrl = Meteor.absoluteUrl() + "dashboard/messages/inbox/thread/" + threadId;
        const body = "Everyspace inbox message received!\n\n" +
            "Hi " + toName + ",\n\n" +
            "You have received a message from " + senderName + " on the Everyspace platform.\n\n" +
            "Access the message here - " + threadUrl + "\n\n" +
            "Thanks,\n" +
            "The Everyspace Crew";

        this.send(toNumber, body);
    }

    static sendUnreadCountSummaryNotification(toNumber: string, toName: string, totalUnreadMessages: number) {
        const inboxUrl = Meteor.absoluteUrl() + "dashboard/messages/inbox";
        const body = "Everyspace inbox message received!\n\n" +
            "Hi " + toName + ",\n\n" +
            "You have " + totalUnreadMessages + " unread messages on the Everyspace platform.\n\n" +
            "Access your inbox here - " + inboxUrl + "\n\n" +
            "Thanks,\n" +
            "The Everyspace Crew";

        this.send(toNumber, body);
    }

}
