openapi: 3.0.3
info:
  title: WABA SAAS API
  description: |
    API Documentation untuk WABA SAAS - WhatsApp Business API Management Platform.
    
    ## Authentication
    Semua endpoint yang memerlukan autentikasi menggunakan **Bearer Token** via Laravel Sanctum.
    
    ```
    Authorization: Bearer {your_api_token}
    ```
    
    ## Base URL
    - Production: `https://your-domain.com/api`
    - Development: `http://localhost:8001/api`
    
    ## Response Format
    Semua response menggunakan format standar:
    
    **Success Response:**
    ```json
    {
      "status": true,
      "message": "Operation successful",
      "data": { ... }
    }
    ```
    
    **Error Response:**
    ```json
    {
      "status": false,
      "message": "Error description",
      "error_code": "ERROR_CODE"
    }
    ```
  version: 1.0.0
  contact:
    name: WABA SAAS Support

servers:
  - url: http://localhost:8001/api
    description: Development Server
  - url: https://your-domain.com/api
    description: Production Server

tags:
  - name: Webhook
    description: Meta WhatsApp Webhook endpoints
  - name: Token Management
    description: WABA Pool token generation and management
  - name: Inbox Messages
    description: Incoming WhatsApp messages management
  - name: Send Message
    description: Outgoing message endpoints

paths:
  /webhook/waba:
    get:
      tags:
        - Webhook
      summary: Verify Webhook (Meta Callback)
      description: Endpoint untuk verifikasi webhook dari Meta
      parameters:
        - name: hub.mode
          in: query
          required: true
          schema:
            type: string
            enum: [subscribe]
        - name: hub.verify_token
          in: query
          required: true
          schema:
            type: string
        - name: hub.challenge
          in: query
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Verifikasi berhasil
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: Token tidak valid

    post:
      tags:
        - Webhook
      summary: Receive Incoming Messages
      description: Endpoint untuk menerima pesan masuk dari Meta WhatsApp API
      responses:
        '200':
          description: Webhook diterima

  /admin/waba-pool/{id}/generate-token:
    post:
      tags:
        - Token Management
      summary: Generate Permanent Token
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                short_lived_token:
                  type: string
                permanent_token:
                  type: string
      responses:
        '200':
          description: Token berhasil di-generate

  /admin/waba-pool/{id}/messages:
    get:
      tags:
        - Inbox Messages
      summary: Get Inbox Messages
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
        - name: date_from
          in: query
          schema:
            type: string
            format: date
        - name: date_to
          in: query
          schema:
            type: string
            format: date
        - name: from_number
          in: query
          schema:
            type: string
        - name: type
          in: query
          schema:
            type: string
        - name: unread_only
          in: query
          schema:
            type: boolean
        - name: per_page
          in: query
          schema:
            type: integer
            default: 50
      responses:
        '200':
          description: List of messages

  /admin/waba-pool/{id}/messages/stats:
    get:
      tags:
        - Inbox Messages
      summary: Get Inbox Statistics
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Inbox statistics

  /admin/waba-pool/{id}/messages/conversations:
    get:
      tags:
        - Inbox Messages
      summary: Get Conversation Threads
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: List of conversations

  /v1/message/send:
    post:
      tags:
        - Send Message
      summary: Send WhatsApp Message
      security:
        - apiKeyAuth: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                to:
                  type: string
                type:
                  type: string
                  enum: [text, template]
                message:
                  type: string
              required:
                - to
      responses:
        '200':
          description: Message sent

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key
