{
  "mode": "declarative",
  "name": "refresh-status",
  "description": "Create or refresh the server status panel.",
  "scope": "guild",
  "defaultMemberPermissions": "32",
  "options": [],
  "actions": [
    {
      "type": "data",
      "dataAction": "load",
      "storeKey": "status_panel"
    },
    {
      "type": "module_action",
      "moduleId": "http-request",
      "moduleAction": "request",
      "moduleInputs": {
        "url": "{setting:status_url}",
        "method": "GET"
      },
      "storeAs": "http"
    },
    {
      "type": "condition",
      "conditionField": "{store:http.ok}",
      "conditionOp": "eq",
      "conditionValue": "true",
      "then": [
        {
          "type": "condition",
          "conditionField": "{store:status_panel}",
          "conditionOp": "eq",
          "conditionValue": "",
          "then": [
            {
              "type": "data",
              "dataAction": "save",
              "storeKey": "status_panel",
              "storeValue": "pending"
            },
            {
              "type": "module_action",
              "moduleId": "message-tools",
              "moduleAction": "send",
              "moduleInputs": {
                "channelId": "{channel.id}",
                "title": "🟢 MX FINDER — {store:http.body.status}",
                "color": "#8b5cf6",
                "description": "Live connection status for MX Central.\nAutomatically checked every **{setting:status_interval} minutes**.\n\nLast heartbeat: <t:{timestamp}:R>\n\n🤖 **Bot Connection**\n🟢 `Connected`\n🌐 **Main Server**\n{store:http.body.mainServer}\n🖥️ **Storage Server**\n{store:http.body.storageServer}\n💾 **Database**\n{store:http.body.database}\n🔎 **Config Search**\n{store:http.body.configSearch}\n📤 **Upload System**\n{store:http.body.uploadSystem}\n☁️ **Cloud Storage**\n{store:http.body.cloudStorage}\n📡 **Discord API**\n🟢 `Connected`\n`{bot.latency} ms`\n⌛ **Uptime**\n`{bot.uptime}`",
                "footer": "MX Central · System Status · Live"
              },
              "storeAs": "panel"
            },
            {
              "type": "data",
              "dataAction": "save",
              "storeKey": "status_panel",
              "storeValue": "{store:panel.messageId}"
            }
          ],
          "else": [
            {
              "type": "module_action",
              "moduleId": "message-tools",
              "moduleAction": "edit",
              "moduleInputs": {
                "channelId": "{channel.id}",
                "title": "🟢 MX FINDER — {store:http.body.status}",
                "color": "#8b5cf6",
                "description": "Live connection status for MX Central.\nAutomatically checked every **{setting:status_interval} minutes**.\n\nLast heartbeat: <t:{timestamp}:R>\n\n🤖 **Bot Connection**\n🟢 `Connected`\n🌐 **Main Server**\n{store:http.body.mainServer}\n🖥️ **Storage Server**\n{store:http.body.storageServer}\n💾 **Database**\n{store:http.body.database}\n🔎 **Config Search**\n{store:http.body.configSearch}\n📤 **Upload System**\n{store:http.body.uploadSystem}\n☁️ **Cloud Storage**\n{store:http.body.cloudStorage}\n📡 **Discord API**\n🟢 `Connected`\n`{bot.latency} ms`\n⌛ **Uptime**\n`{bot.uptime}`",
                "footer": "MX Central · System Status · Live",
                "messageId": "{store:status_panel}"
              },
              "storeAs": "panel"
            }
          ]
        }
      ],
      "else": [
        {
          "type": "condition",
          "conditionField": "{store:status_panel}",
          "conditionOp": "eq",
          "conditionValue": "",
          "then": [
            {
              "type": "data",
              "dataAction": "save",
              "storeKey": "status_panel",
              "storeValue": "pending"
            },
            {
              "type": "module_action",
              "moduleId": "message-tools",
              "moduleAction": "send",
              "moduleInputs": {
                "channelId": "{channel.id}",
                "title": "🔴 MX FINDER — Status unavailable",
                "description": "The status endpoint could not be reached or returned an error.\n\nLast attempt: <t:{timestamp}:R>\nHTTP status: {store:http.status}",
                "color": "#ed4245",
                "footer": "MX Central · System Status · Live"
              },
              "storeAs": "panel"
            },
            {
              "type": "data",
              "dataAction": "save",
              "storeKey": "status_panel",
              "storeValue": "{store:panel.messageId}"
            }
          ],
          "else": [
            {
              "type": "module_action",
              "moduleId": "message-tools",
              "moduleAction": "edit",
              "moduleInputs": {
                "channelId": "{channel.id}",
                "title": "🔴 MX FINDER — Status unavailable",
                "description": "The status endpoint could not be reached or returned an error.\n\nLast attempt: <t:{timestamp}:R>\nHTTP status: {store:http.status}",
                "color": "#ed4245",
                "footer": "MX Central · System Status · Live",
                "messageId": "{store:status_panel}"
              },
              "storeAs": "panel"
            }
          ]
        }
      ]
    }
  ]
}
