-- Seed the "crowd-favorite" badge — progression medal for users whose
-- media receive Like reactions from OTHER users. Self-reactions are
-- impossible (blocked at the service layer by SelfReact guard), so no
-- filtering is needed beyond `value = 'like'`.
--
-- Design:
--   - 5-tier progression (`type = 'level'`), thresholds 25/100/500/2000/10000.
--     Wider spacing than `shutterbug`/`wordsmith` (×4..×5 between tiers)
--     because likes are PASSIVE — the recipient cannot force them and
--     the cumulative count grows organically with reach.
--   - XP rewards are SLIGHTLY MORE GENEROUS than the active-effort
--     badges (50/150/400/1000/2500 → 4100 cumulative across L1..L5,
--     vs shutterbug 2600 and wordsmith 2000): likes received are a
--     quality signal from peers, worth the bonus.
--   - `position = 40` slots the badge after `wordsmith` (30) in the
--     catalogue listing.
--   - Metric is `reaction.like.received` (see `BadgeMetric::ReactionLikeReceived`).
--     The emitter is `MediaReactionService::react()` AFTER the upsert,
--     gated by the same condition used for the notification:
--     `existing === null && value === Like` (brand-new like only; flips
--     and re-likes after unlike are handled by the trigger semantics).
--
-- Idempotency: INSERT IGNORE + slug-as-natural-key make the migration
-- safe to re-run.

INSERT IGNORE INTO `badge`
    (`id`, `slug`, `type`, `metric`, `position`, `is_active`, `created_at`)
VALUES
    (UNHEX(REPLACE(UUID(), '-', '')),
     'crowd-favorite',
     'level',
     'reaction.like.received',
     40,
     1,
     NOW());

INSERT IGNORE INTO `badge_tier`
    (`badge_id`, `level`, `threshold`, `xp_reward`)
SELECT `id`, 1,    25,   50 FROM `badge` WHERE `slug` = 'crowd-favorite'
UNION ALL
SELECT `id`, 2,   100,  150 FROM `badge` WHERE `slug` = 'crowd-favorite'
UNION ALL
SELECT `id`, 3,   500,  400 FROM `badge` WHERE `slug` = 'crowd-favorite'
UNION ALL
SELECT `id`, 4,  2000, 1000 FROM `badge` WHERE `slug` = 'crowd-favorite'
UNION ALL
SELECT `id`, 5, 10000, 2500 FROM `badge` WHERE `slug` = 'crowd-favorite';
