/**
 Allows user to send messages to the Telegram API.
 */

const TelegramBot = require('node-telegram-bot-api');
const config = require('../../config');

const token = config.telegram.authToken;

const bot = new TelegramBot(token, {
  polling: false
});

module.exports = {
  sendMessage(subarea, message) {
    bot.sendMessage(config.telegram.chats[subarea], message);
  },
  sendHint(subarea, lat, lng, address) {
    bot.sendMessage(config.telegram.chats[subarea], `🧩 ${subarea} naar ${address}. Toon op Google Maps: https://www.google.com/maps/search/?api=1&query=${lat},${lng}`);
    bot.sendLocation(config.telegram.chats[subarea], lat, lng);
  },
  sendHunt(subarea, lat, lng, address, createdAt) {
    // Get next hunt time
    createdAtDate = new Date(createdAt);
    createdAtDate.setHours(createdAtDate.getHours() + 1)
    const time = (createdAtDate.getHours() + 2) + ':' + createdAtDate.getMinutes();

    bot.sendMessage(config.telegram.chats[subarea], `🔫 Hunt op ${address} voor ${subarea}!
      1. Geef correcte tijd en locatie door aan de thuisbasis.
      2. Vul je hunt in via www.jotihunt.net met gebruikersnaam \`jotihunt@scouting-ijsselgroep.nl\` en wachtwoord
\`scouting70lordbaden\`.
      3. De vossen mogen pas om ${time} uur weer gehunt worden.
      4. Bepaal de taktiek voor het komende uur.`);
    // bot.sendLocation(config.telegram.chats[subarea], lat, lng);
  },
  sendSimpleLocation(subarea, lat, lng, address) {
    bot.sendMessage(config.telegram.chats[subarea], `${subarea} op ${address}. Toon op Google Maps: https://www.google.com/maps/search/?api=1&query=${lat},${lng}`);
    bot.sendLocation(config.telegram.chats[subarea], lat, lng);
  },
};
@@ -298,24 +298,62 @@
  message) %7B%0A
+    if (process.env.SEND_MESSAGE) %7B%0A  
     bot.send
@@ -402,16 +402,22 @@
 ssage);%0A
+    %7D%0A
   %7D,%0A  s
@@ -446,32 +446,70 @@
 lng, address) %7B%0A
+    if (process.env.SEND_MESSAGE) %7B%0A  
     bot.sendMess
@@ -577,96 +577,14 @@
 ess%7D
-. Toon op Google Maps: https://www.google.com/maps/search/?api=1&query=$%7Blat%7D,$%7Blng%7D
 %60);%0A
+  
     
@@ -635,32 +635,38 @@
 ea%5D, lat, lng);%0A
+    %7D%0A
   %7D,%0A  sendHunt(
@@ -702,24 +702,62 @@
 reatedAt) %7B%0A
+    if (process.env.SEND_MESSAGE) %7B%0A  
     // Get n
@@ -770,16 +770,18 @@
 nt time%0A
+  
     crea
@@ -813,24 +813,26 @@
 tedAt);%0A    
+  
 createdAtDat
@@ -872,16 +872,18 @@
 () + 1)%0A
+  
     cons
@@ -959,24 +959,26 @@
 tes();%0A%0A    
+  
 bot.sendMess
@@ -1052,16 +1052,18 @@
 barea%7D!%0A
+  
       1.
@@ -1123,16 +1123,18 @@
 .%0A      
+  
 2. Vul j
@@ -1161,18 +1161,17 @@
 tihunt.n
-et
+l
  met geb
@@ -1188,82 +1188,99 @@
 m %5C%60
-jotihunt@scouting-ijsselgroep.nl%5C%60 en wachtwoord%0A%5C%60scouting70lordbaden
+$%7Bprocess.env.JOTIHUNT_USERNAME%7D%5C%60 en wachtwoord%0A  %5C%60$%7Bprocess.env.JOTIHUNT_PASSWORD%7D
 %5C%60.%0A
+  
     
@@ -1345,16 +1345,18 @@
 .%0A      
+  
 4. Bepaa
@@ -1401,70 +1401,9 @@
     
-// bot.sendLocation(config.telegram.chats%5Bsubarea%5D, lat, lng);
+%7D
 %0A  %7D
@@ -1451,24 +1451,62 @@
  address) %7B%0A
+    if (process.env.SEND_MESSAGE) %7B%0A  
     bot.send
@@ -1574,96 +1574,14 @@
 ess%7D
-. Toon op Google Maps: https://www.google.com/maps/search/?api=1&query=$%7Blat%7D,$%7Blng%7D
 %60);%0A
+  
     
@@ -1640,15 +1640,21 @@
 , lng);%0A
+    %7D%0A
   %7D,%0A%7D;

Disable messages on debug mode