-- TRAIL DPS 4.2 - LOT 11.21
-- Verification non destructive : recalculs usage licence et fenetre courses 300 jours.

-- 1) Derniers checks licence et marqueur serveur attendu.
SELECT id, license_id, event_type, created_at, payload_json
FROM license_audit_log
WHERE event_type IN ('check', 'usage_persist_error')
ORDER BY id DESC
LIMIT 20;

-- 2) Derniers snapshots PLACE transmis par TRAIL DPS.
SELECT id, license_id, computed_at, rolling_365_course_count AS rolling_300_course_count_legacy_column,
       sms_sent_count, active_events_count, active_runs_count, source, details_json, created_at
FROM license_usage_stats
WHERE source = 'PLACE_LICENSE_CHECK'
ORDER BY id DESC
LIMIT 20;

-- 3) Controle des details JSON : usage_window_days doit valoir 300 sur les nouvelles lignes.
SELECT id, JSON_EXTRACT(details_json, '$.usage_window_days') AS usage_window_days,
       JSON_EXTRACT(details_json, '$.rolling_300_course_count') AS rolling_300_course_count,
       JSON_EXTRACT(details_json, '$.trigger') AS trigger_reason
FROM license_usage_stats
ORDER BY id DESC
LIMIT 20;
