#!/bin/bash

if [ $# -lt 1 ]; then
  echo -e "WEBHOOK_URL var" && exit
fi

WEBHOOK_DATA='{
  "content": null,
  "embeds": [
    {
      "title": "AzubiTool Deployment",
      "description": "Eine neue Version vom Azubitool wurde hochgeladen und wird in Kürze auf den Server deployt.\nBitte rechnet mit einer Downtime von maximal 5 Minuten.\nSollten Fehler auftreten, bemerken wir das schon (irgendwann - hoffentlich)\n\nAnsonsten erstmal Ciao for now, man liest sich bestimmt bald wieder.",
      "url": "http://azubitool.rhrk.uni-kl.de/",
      "color": 60159,
      "author": {
        "name": "INFORMATION",
        "url": "http://azubitool.rhrk.uni-kl.de/",
        "icon_url": "https://i.imgur.com/MijSgr5.png"
      },
      "thumbnail": {
        "url": "https://i.imgur.com/MijSgr5.png"
      }
    }
  ],
  "username": "Sr AzubiDev",
  "avatar_url": "https://gitlab.com/favicon.png",
  "attachments": []
}'

for ARG in "$@"; do
  echo -e "[Webhook]: Sende Webhook zu Discord...\\n";

  (curl --fail --progress-bar -A "GitLabCI-Webhook" -H Content-Type:application/json -H X-Author:heist_rhrk -d "$WEBHOOK_DATA" "$ARG" \
  && echo -e "\\n[Webhook]: Erfolgreich Benachrichtigt.") || echo -e "\\n[Webhook]: Konnte Webhook nicht senden."
done