-- 🔍 Trouver l'abonnement pour un user_id spécifique

-- Remplacer USER_ID par : 3907a1cc-87db-4d5b-bbe7-d56f96cdb120

SELECT 
  us.id as subscription_db_id,
  us.stripe_subscription_id,
  us.stripe_customer_id,
  us.user_id,
  u.email,
  us.status,
  us.plan_id,
  us.is_yearly,
  us.auto_renew,
  us.current_period_start,
  us.current_period_end,
  us.created_at,
  us.updated_at,
  -- Vérifier si la période est valide
  CASE 
    WHEN us.current_period_end > NOW() THEN '✅ ACTIF'
    WHEN us.current_period_end < NOW() THEN '⚠️ EXPIRÉ'
    ELSE '❓ INCONNU'
  END as period_status,
  -- Jours restants
  EXTRACT(DAY FROM us.current_period_end - NOW()) as jours_restants
FROM user_subscriptions us
LEFT JOIN auth.users u ON u.id = us.user_id
WHERE us.user_id = '3907a1cc-87db-4d5b-bbe7-d56f96cdb120'
ORDER BY us.created_at DESC;

