const express = require("express");
const PongPlugin = require("./pong_plugin");

const pluginUrn = "urn:john.caringal:order-insight:0";
const crispAPIIdentifier = "65ad163b-705d-45b6-a10d-763404858128";
const crispAPIKey = "c0fa7398942236fa26b12db0dbb9b0c61b62750c814f1e0a957afaf33cc70349";

const app = express();
const port = 1234;

const plugin = new PongPlugin(
  pluginUrn,
  crispAPIIdentifier,
  crispAPIKey
);

app.use(express.json());

app.use("/", express.static("public"));

app.use("/config/update", ((req) => {
    const websiteId = req.body.website_id;
    const message = req.body.message;
    const token = req.body.token;

    plugin.updateMessageForWebsite(websiteId, token, message)
}));

app.listen(port, () => {
    console.log(`Plugin now listening on port :${port}`)
});
