{{ define "apidoc.pages.tmpl" }}
{{ template "head" . }}
<div class="columns">
    {{ template "sidebar" . }}
  
    <div class="column is-10">
<div class="section">
  <h1 class="title">📘 API WhatsApp SaaS – Documentation JSON</h1>

  <div class="content">
    <p>Tu peux utiliser ces endpoints via Postman, PHP (cURL) ou JS. Toutes les requêtes POST attendent du JSON dans le corps et certaines nécessitent un JWT dans un <code>token</code> ou un <code>cookie</code>.</p>
  </div>

  <div class="box">
    <h2 class="subtitle">🔐 Authentification</h2>
    <p><strong>POST /api/login</strong></p>
    <pre><code>{
  "email": "admin@example.com",
  "password": "motdepasse"
}</code></pre>

    <p><strong>Retour</strong> : Cookie "token" et JSON <code>{"message":"Login success"}</code></p>
  </div>

  <div class="box">
    <h2 class="subtitle">📤 Envoi message simple</h2>
    <p><strong>POST /api/message/send</strong> <em>(nécessite token)</em></p>
    <pre><code>{
  "to": "33612345678",
  "type": "text",
  "text": {
    "body": "Bonjour depuis l'API"
  },
  "token": "votre_jwt_token_si_poster_via_JSON"
}</code></pre>
  </div>

  <div class="box">
    <h2 class="subtitle">📤 Envoi message template</h2>
    <p><strong>POST /api/message/send2</strong></p>
    <pre><code>{
        "to": "33612345678",
        "template_name": "hello_world",
        "language": "fr",
        "param1": "Jean",
        "param2": "commande #1234",
        "param3": "optionnel",
        "param4": "optionnel",
        "param5": "optionnel",
        "token": "votre_jwt_token"
      }</code></pre>
  </div>

  <div class="box">
    <h2 class="subtitle">📥 Webhook WhatsApp</h2>
    <p><strong>GET /api/whatsapp/webhook</strong> <em>(vérification)</em><br>
    Envoyer <code>?hub.mode=subscribe&hub.verify_token=secrettoken&hub.challenge=123</code></p>

    <p><strong>POST /api/whatsapp/webhook</strong> <em>(callback messages/statuts)</em></p>
  </div>

  <div class="box">
    <h2 class="subtitle">👤 Utilisateurs (admin uniquement)</h2>

    <p><strong>POST /api/user/create</strong></p>
    <pre><code>{
  "email": "client@demo.com",
  "password": "secret",
  "sso_id": "CLIENT123",
  "role": "CLIENT",
  "is_active": true,
  "whatsapp_token": "EAAxxxxx",
  "whatsapp_phone_number_id": "123456789",
  "monthly_credits": 100
}</code></pre>

    <p><strong>PUT /api/user/update/{id}</strong></p>
    <pre><code>{
  "email": "nouveau@demo.com",
  "is_active": true,
  "monthly_credits": 200
}</code></pre>

    <p><strong>DELETE /api/user/delete/{id}</strong></p>
  </div>

  <div class="box">
    <h2 class="subtitle">💬 Conversations</h2>
    <p><strong>GET /api/user/{id}/conversations</strong></p>
    <p>Filtrable avec <code>?type=text</code> ou <code>?filter=today</code></p>

    <p><strong>GET /admin/user/{id}/conversation-thread</strong><br>(Vue HTML pour un utilisateur)</p>
  </div>
</div>
</div>
</div>
{{ end }}
