{
  "openapi": "3.0.0",
  "info": {
    "title": "BitUp Status API",
    "description": "Officiellt API för BitUp Hosting – levererar realtidsdata för monitorer, incidenter och systemstatistik. Bygg egna dashboards och integrationer på nolltid.",
    "version": "2.1.0",
    "contact": {
      "name": "BitUp Support",
      "email": "support@bitup.se",
      "url": "https://bitup.se"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://bitup.se/terms"
    },
    "x-logo": {
      "url": "https://status.bitup.se/bitup-logo.png",
      "altText": "BitUp Logo"
    }
  },
  "servers": [
    {
      "url": "https://status.bitup.se",
      "description": "Produktionsserver"
    },
    {
      "url": "https://staging.status.bitup.se",
      "description": "Staging-miljö (endast internt bruk)"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "query",
        "name": "key",
        "description": "Personlig API-nyckel som genereras i adminpanelen."
      }
    },
    "schemas": {
      "ApiResponse": {
        "type": "object",
        "required": [
          "status",
          "api_version",
          "data"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "success",
              "error"
            ],
            "description": "Status för API-anropet"
          },
          "api_version": {
            "type": "string",
            "example": "2.1",
            "description": "Aktuell API-version"
          },
          "data": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/MonitorArray"
              },
              {
                "$ref": "#/components/schemas/CategoryArray"
              },
              {
                "$ref": "#/components/schemas/IncidentArray"
              },
              {
                "$ref": "#/components/schemas/Stats"
              }
            ],
            "description": "Dynamisk data baserad på action-parametern"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "status",
          "message"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "error"
            ]
          },
          "message": {
            "type": "string",
            "description": "Detaljerad felbeskrivning"
          }
        }
      },
      "Monitor": {
        "type": "object",
        "required": [
          "id",
          "name",
          "type",
          "target",
          "status",
          "last_check",
          "category_id"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unikt ID för monitorn"
          },
          "name": {
            "type": "string",
            "description": "Beskrivande namn på monitorn"
          },
          "type": {
            "type": "string",
            "enum": [
              "http",
              "ping",
              "tcp"
            ],
            "description": "Typ av monitor"
          },
          "target": {
            "type": "string",
            "description": "Mål-URL eller IP-adress"
          },
          "port": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Portnummer (om tillämpligt)"
          },
          "status": {
            "type": "string",
            "enum": [
              "up",
              "down",
              "pending",
              "maintenance"
            ],
            "description": "Aktuell status"
          },
          "last_check": {
            "type": "string",
            "format": "date-time",
            "description": "Senaste kontrolltid (Y-m-d H:i:s)"
          },
          "is_active": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "Om monitorn är aktiv"
          },
          "category_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID för kategorin monitorn tillhör"
          },
          "category_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Namn på kategorin (vid JOIN)"
          }
        }
      },
      "SimpleMonitor": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "up",
              "down",
              "pending",
              "maintenance"
            ]
          },
          "category": {
            "type": "string",
            "description": "Kategorinamn"
          }
        }
      },
      "Category": {
        "type": "object",
        "required": [
          "id",
          "name",
          "display_order"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unikt kategori-ID"
          },
          "name": {
            "type": "string",
            "description": "Kategorinamn"
          },
          "display_order": {
            "type": "integer",
            "description": "Visningsordning (lägre = först)"
          },
          "monitor_count": {
            "type": "integer",
            "description": "Antal monitorer i kategorin"
          },
          "up_count": {
            "type": "integer",
            "description": "Antal uppe-monitorer i kategorin"
          },
          "down_count": {
            "type": "integer",
            "description": "Antal nere-monitorer i kategorin"
          },
          "monitors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Monitor"
            },
            "description": "Lista över monitorer i kategorin (endast vid specifik category-förfrågan)"
          }
        }
      },
      "Incident": {
        "type": "object",
        "required": [
          "id",
          "title",
          "type",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unikt incident-ID"
          },
          "title": {
            "type": "string",
            "description": "Incidentrubrik"
          },
          "type": {
            "type": "string",
            "enum": [
              "info",
              "maintenance",
              "down"
            ],
            "description": "Typ av incident"
          },
          "is_active": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "Om incidenten är aktiv"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Skapad datum"
          },
          "monitors": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Lista med namn på berörda monitorer"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Lista med namn på berörda kategorier"
          },
          "updates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/IncidentUpdate"
            },
            "description": "Tidslinje med uppdateringar"
          }
        }
      },
      "IncidentUpdate": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Uppdateringsmeddelande"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Tid för uppdateringen"
          }
        }
      },
      "Stats": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Totalt antal monitorer"
          },
          "online": {
            "type": "integer",
            "description": "Antal monitorer som är uppe"
          },
          "offline": {
            "type": "integer",
            "description": "Antal monitorer som är nere"
          },
          "uptime_percent": {
            "type": "number",
            "format": "float",
            "description": "Total uptime-procent"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "category_name": {
                  "type": "string"
                },
                "total_in_category": {
                  "type": "integer"
                },
                "up_in_category": {
                  "type": "integer"
                },
                "down_in_category": {
                  "type": "integer"
                },
                "uptime_percent_category": {
                  "type": "number",
                  "format": "float"
                }
              }
            },
            "description": "Statistik uppdelad per kategori"
          }
        }
      },
      "CategoryGroup": {
        "type": "object",
        "properties": {
          "category_id": {
            "type": "integer"
          },
          "category_name": {
            "type": "string"
          },
          "monitors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Monitor"
            }
          }
        }
      },
      "MonitorArray": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Monitor"
        }
      },
      "SimpleMonitorArray": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/SimpleMonitor"
        }
      },
      "CategoryGroupArray": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/CategoryGroup"
        }
      },
      "CategoryArray": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Category"
        }
      },
      "IncidentArray": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Incident"
        }
      }
    },
    "parameters": {
      "keyParam": {
        "name": "key",
        "in": "query",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "Din personliga API-nyckel"
      },
      "actionParam": {
        "name": "action",
        "in": "query",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "status",
            "categories",
            "incidents",
            "stats",
            "category"
          ]
        },
        "description": "Vilken typ av data du vill hämta"
      },
      "formatParam": {
        "name": "format",
        "in": "query",
        "required": false,
        "schema": {
          "type": "string",
          "enum": [
            "full",
            "simple",
            "grouped"
          ],
          "default": "full"
        },
        "description": "Format på svaret (endast för action=status)"
      },
      "categoryIdParam": {
        "name": "category_id",
        "in": "query",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Kategori-ID (krävs för action=category)"
      }
    },
    "responses": {
      "SuccessResponse": {
        "description": "Framgångsrikt anrop",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiResponse"
            }
          }
        }
      },
      "BadRequest": {
        "description": "Ogiltig parameter eller saknat fält",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "status": "error",
              "message": "category_id required"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Saknad eller ogiltig API-nyckel",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "missing": {
                "value": {
                  "status": "error",
                  "message": "API key missing. Please provide a valid ?key="
                }
              },
              "invalid": {
                "value": {
                  "status": "error",
                  "message": "Invalid API key. Access denied."
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Resurs hittades inte",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "status": "error",
              "message": "Category not found"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api.php": {
      "get": {
        "summary": "Huvudendpoint för API:et",
        "description": "Returnerar data baserat på action-parametern. Alla anrop kräver en giltig API-nyckel.",
        "operationId": "getApiData",
        "parameters": [
          {
            "$ref": "#/components/parameters/keyParam"
          },
          {
            "$ref": "#/components/parameters/actionParam"
          },
          {
            "$ref": "#/components/parameters/formatParam"
          },
          {
            "$ref": "#/components/parameters/categoryIdParam"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/SuccessResponse"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "tags": [
          "Public API"
        ],
        "x-examples": {
          "status_full": {
            "summary": "Hämta alla monitorer (fullt format)",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=status&format=full'"
          },
          "status_simple": {
            "summary": "Hämta alla monitorer (enkelt format)",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=status&format=simple'"
          },
          "status_grouped": {
            "summary": "Hämta monitorer grupperade per kategori",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=status&format=grouped'"
          },
          "categories": {
            "summary": "Hämta alla kategorier med statistik",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=categories'"
          },
          "category_specific": {
            "summary": "Hämta specifik kategori med dess monitorer",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=category&category_id=1'"
          },
          "incidents": {
            "summary": "Hämta aktiva incidenter",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=incidents'"
          },
          "stats": {
            "summary": "Hämta systemstatistik med kategoriuppdelning",
            "value": "curl 'https://status.bitup.se/api.php?key=din_nyckel&action=stats'"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Public API",
      "description": "Öppna endpoints för statusdata"
    }
  ],
  "externalDocs": {
    "description": "Fullständig dokumentation och adminpanel",
    "url": "https://status.bitup.se/admin/"
  }
}