const express = require("express");
const router = express.Router();
const twilio = require("twilio");
const { receive } = require("../sms/receive");
const { send } = require("../sms/send");
const { status, markConversationRead, markLastMessageUnread } = require("../sms/status");
const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware");

// Twilio Webhook Middleware for production
// TODO: This is never actually doing anything, we should probably verify
const twilioWebhookMiddleware = twilio.webhook({ validate: process.env.NODE_ENV === "PRODUCTION" });

router.post("/receive", twilioWebhookMiddleware, receive);
router.post("/send", validateFirebaseIdTokenMiddleware, send);
router.post("/status", twilioWebhookMiddleware, status);
router.post("/markConversationRead", validateFirebaseIdTokenMiddleware, markConversationRead);
router.post("/markLastMessageUnread", validateFirebaseIdTokenMiddleware, markLastMessageUnread);

module.exports = router;
