const { bigcommerceApiOAuth, serverBaseURL, bigcommerceStoreHash } = require("../config.js")
const { deletePrintfulWebhook } = require("../lib/printfulRestAPI.js")
;(function () {
    const data = context.data
    if (context?.user?.auth()?.id) {
        const webhook = context.db.find("webhook", {
            filter: {
                _id: context.request().param("id"),
            },
        })[0]

        if (webhook.type === "printful") {
            deletePrintfulWebhook(webhook.scope)
        } else {
            let url = `https://api.bigcommerce.com/stores/${bigcommerceStoreHash}/v3/hooks/${webhook.webhookId}`

            let options = {
                method: "DELETE",
                headers: { "Content-Type": "application/json", "X-Auth-Token": bigcommerceApiOAuth },
            }

            const response = context.http.fetch(url, options).body.json()
        }
    }
})()
