-- Script para debugar mensagens

-- 1. Ver todas as mensagens
SELECT 
    id,
    sender_id,
    receiver_id,
    content,
    read,
    created_at
FROM public.messages
ORDER BY created_at DESC
LIMIT 20;

-- 2. Ver IDs únicos de remetentes e destinatários
SELECT 'Remetentes únicos:' as tipo, sender_id as user_id FROM public.messages
UNION
SELECT 'Destinatários únicos:', receiver_id FROM public.messages
ORDER BY tipo, user_id;

-- 3. Contar mensagens por remetente
SELECT 
    sender_id,
    COUNT(*) as total_enviadas
FROM public.messages
GROUP BY sender_id;

-- 4. Contar mensagens por destinatário
SELECT 
    receiver_id,
    COUNT(*) as total_recebidas
FROM public.messages
GROUP BY receiver_id;
