#!/usr/bin/env python3
"""
Quick test call_followup - process only first 5 leads
"""
import sys
sys.path.insert(0, '/home/ubuntu/GhostAgency')

from call_followup_v3 import *
import os

# Quick test with just first 5 leads
def quick_test():
    print(f"\n{'='*60}")
    print(f" CALL FOLLOWUP v3 - QUICK TEST (5 leads)")
    print(f"{'='*60}\n")
    
    if not CALL_LIST_CSV.exists():
        print("[!] call_list.csv non trovato")
        return
    
    leads = []
    with open(CALL_LIST_CSV, newline="", encoding="utf-8") as f:
        reader = csv.DictReader(f)
        for row in reader:
            leads.append(row)
    
    if not leads:
        print("[=] Nessun lead nella call list")
        return
    
    test_leads = leads[:5]
    print(f"[*] Trovati {len(leads)} lead totali, testando primi {len(test_leads)}")
    print(f"[*] Provider: manual\n")
    
    for i, lead in enumerate(test_leads):
        nome = lead.get("Nome", "").strip()
        telefono = lead.get("Telefono", "").strip()
        categoria = lead.get("Categoria", "").strip()
        
        if not nome or not telefono:
            continue
        
        wa_number = format_whatsapp_number(telefono)
        template_version = select_template(i)
        template = TEMPLATES[template_version]
        body = template["body"].format(nome=nome)
        
        print(f"\n[{i+1}/{len(test_leads)}] {nome} ({categoria}) -> {wa_number}")
        print(f"    Template: {template_version}")
        print(f"    Message: {body[:80]}...")
        
        # Save manual file
        message_sid, error = send_whatsapp_manual(wa_number, body, nome, template_version)
        if error:
            print(f"    [!] Errore: {error}")
        else:
            print(f"    [+] File creato: {message_sid}")
    
    print(f"\n{'='*60}")
    print(f"TEST COMPLETATO - File in {OUTPUT_DIR}")
    print(f"{'='*60}")

if __name__ == "__main__":
    quick_test()