{
  "openapi": "3.0.0",
  "info": {
    "title": "Orbit WhatsApp Bot API",
    "description": "API komprehensif untuk mengintegrasikan fungsionalitas WhatsApp ke dalam aplikasi Anda. Mendukung pengiriman pesan teks, media (gambar), manajemen device, dan pelacakan status pengiriman secara real-time.",
    "version": "1.3.0",
    "contact": {
      "name": "Orbit Support",
      "url": "https://orbitwaapi.site"
    }
  },
  "servers": [
    {
      "url": "https://orbitwaapi.site/api",
      "description": "Production Server"
    },
    {
      "url": "http://localhost:8000/api",
      "description": "Local Development"
    }
  ],
  "paths": {
    "/auth/register": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "summary": "Mendaftarkan Pengguna Baru",
        "description": "Membuat akun baru untuk mendapatkan akses ke dashboard dan API Key.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "email",
                  "password",
                  "password_confirmation"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Budi Santoso"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "budi@example.com"
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "example": "rahasia123"
                  },
                  "password_confirmation": {
                    "type": "string",
                    "format": "password",
                    "example": "rahasia123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registrasi berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "User successfully registered"
                    },
                    "user": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "integer" },
                        "name": { "type": "string" },
                        "email": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validasi gagal (Email sudah terdaftar, password tidak cocok, dll)"
          }
        }
      }
    },
    "/auth/login": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "summary": "Login & Dapatkan Bearer Token",
        "description": "Gunakan email dan password Anda untuk mendapatkan JWT Bearer Token yang valid selama 60 menit.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "budi@example.com"
                  },
                  "password": {
                    "type": "string",
                    "example": "rahasia123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login berhasil, mengembalikan Access Token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "access_token": {
                      "type": "string",
                      "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
                    },
                    "token_type": {
                      "type": "string",
                      "example": "bearer"
                    },
                    "expires_in": {
                      "type": "integer",
                      "example": 3600
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Kredensial salah"
          }
        }
      }
    },
    "/v1/messages/send": {
      "post": {
        "tags": [
          "WhatsApp Messages"
        ],
        "summary": "Kirim Pesan atau Gambar",
        "description": "Endpoint utama untuk mengirim pesan WhatsApp. Sistem akan otomatis memilih device yang berstatus 'connected' jika `device_id` tidak ditentukan.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "to",
                  "message"
                ],
                "properties": {
                  "to": {
                    "type": "string",
                    "description": "Nomor tujuan (disarankan format internasional tanpa '+', misal: 62812...)",
                    "example": "6285218574781"
                  },
                  "message": {
                    "type": "string",
                    "description": "Isi pesan teks",
                    "example": "Halo dari Orbit API! Pesan ini dikirim secara real-time. 🚀"
                  },
                  "file": {
                    "type": "string",
                    "format": "url",
                    "description": "URL gambar yang ingin dikirim (opsional)",
                    "example": "https://orbitwaapi.site/Image/logo-wa-api-black.png"
                  },
                  "device_id": {
                    "type": "integer",
                    "description": "Gunakan ID device tertentu jika Anda memiliki banyak device (opsional)",
                    "example": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pesan berhasil diproses oleh gateway",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message_status": {
                      "type": "string",
                      "example": "Success"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "from": { "type": "string", "example": "628123456789" },
                        "to": { "type": "string", "example": "6285218574781" },
                        "message_id": { "type": "string", "example": "MSG-30005-20260314" },
                        "status": { "type": "string", "example": "sent" },
                        "timestamp": { "type": "string", "format": "date-time", "example": "2026-03-14T17:37:26+00:00" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Tidak ada device yang terhubung",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message_status": { "type": "string", "example": "Error" },
                    "error": { "type": "string", "example": "No connected device available" }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Token Bearer tidak valid atau kadaluwarsa"
          }
        }
      }
    },
    "/v1/messages/{id}/status": {
      "get": {
        "tags": [
          "WhatsApp Messages"
        ],
        "summary": "Cek Status Pengiriman",
        "description": "Mengetahui apakah pesan sudah terkirim (sent), diterima (delivered), atau dibaca (read).",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID Pesan Eksternal (format: MSG-XXXXX-YYYYMMDD)",
            "schema": {
              "type": "string",
              "example": "MSG-30003-20260314"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Detail status pengiriman",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message_id": { "type": "string", "example": "MSG-30003-20260314" },
                    "status": { "type": "string", "enum": ["pending", "sent", "delivered", "read", "failed"], "example": "read" },
                    "sent_at": { "type": "string", "format": "date-time" },
                    "delivered_at": { "type": "string", "format": "date-time" },
                    "read_at": { "type": "string", "format": "date-time" }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Pesan tidak ditemukan"
          }
        }
      }
    },
    "/v1/devices": {
      "get": {
        "tags": [
          "Devices"
        ],
        "summary": "Daftar Device WhatsApp",
        "description": "Mendapatkan daftar semua device yang terdaftar di akun Anda beserta status koneksinya.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Daftar device berhasil diambil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "integer", "example": 1 },
                      "name": { "type": "string", "example": "Samsung S21" },
                      "phone_number": { "type": "string", "example": "62812345678" },
                      "status": { "type": "string", "enum": ["connected", "disconnected", "error"], "example": "connected" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  }
}

