-- LOT 11.18 - Verification affichage admin supervision commerciale
-- Objectif : verifier que les courses/evenements/runs proviennent de PLACE_LICENSE_CHECK
-- et que les SMS proviennent du dernier snapshot OVH_SMS_*.
-- Requete non destructive.

SET @license_id := 1;

SELECT
    'PLACE_USAGE_SOURCE' AS controle,
    id,
    license_id,
    computed_at,
    rolling_365_course_count,
    active_events_count,
    active_runs_count,
    source
FROM license_usage_stats
WHERE license_id = @license_id
  AND source = 'PLACE_LICENSE_CHECK'
ORDER BY computed_at DESC, id DESC
LIMIT 1;

SELECT
    'SMS_USAGE_SOURCE' AS controle,
    id,
    license_id,
    computed_at,
    sms_sent_count,
    source
FROM license_usage_stats
WHERE license_id = @license_id
  AND computed_at >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 365 DAY)
  AND sms_sent_count > 0
  AND source LIKE 'OVH_SMS%'
ORDER BY computed_at DESC, id DESC
LIMIT 1;

SELECT
    'ALL_RECENT_USAGE_ROWS' AS controle,
    id,
    license_id,
    computed_at,
    rolling_365_course_count,
    sms_sent_count,
    active_events_count,
    active_runs_count,
    source
FROM license_usage_stats
WHERE license_id = @license_id
ORDER BY id DESC
LIMIT 10;
