-- =====================================================
-- Seed: gamification_system.achievements (PROD)
-- Description: Logros y achievements demo para testing y producci�n
-- Environment: PRODUCTION
-- Dependencies: gamification_system.achievement_categories
-- Order: 04
-- Created: 2025-01-11
-- Version: 1.0
-- =====================================================
--
-- ACHIEVEMENTS INCLUIDOS:
-- - Progress (5): Primeros pasos, ejercicios completados, progreso
-- - Streak (3): Rachas de d�as consecutivos
-- - Completion (4): Completaci�n de m�dulos
-- - Mastery (3): Dominio y maestr�a
-- - Exploration (2): Exploraci�n de contenido
-- - Social (2): Interacci�n social
-- - Special (1): Logro especial
--
-- TOTAL: 30 achievements demo (20 originales + 10 nuevos shop/engagement)
--
-- IMPORTANTE: Estos achievements cubren casos de uso comunes
-- del sistema educativo de comprensi�n lectora GAMILIT.
-- =====================================================

SET search_path TO gamification_system, educational_content, public;

-- =====================================================
-- INSERT: Achievements Demo
-- =====================================================

INSERT INTO gamification_system.achievements (
    id,
    tenant_id,
    name,
    description,
    icon,
    category,
    rarity,
    difficulty_level,
    conditions,
    rewards,
    ml_coins_reward,
    is_secret,
    is_active,
    is_repeatable,
    order_index,
    points_value,
    unlock_message,
    instructions,
    tips,
    metadata,
    created_at,
    updated_at
) VALUES

-- =====================================================
-- CATEGORY: PROGRESS (5 achievements)
-- =====================================================

-- 1. Primeros Pasos
(
    '90000001-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,  -- Tenant principal
    'Primeros Pasos',
    'Completa tu primer ejercicio de comprensi�n lectora',
    '<�',
    'progress'::gamification_system.achievement_category,
    'common',
    'beginner'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exercise_completion',
        'requirements', jsonb_build_object(
            'exercises_completed', 1
        )
    ),
    jsonb_build_object(
        'xp', 50,
        'ml_coins', 10,
        'badge', 'first_steps'
    ),
    10,
    false,
    true,
    false,
    1,
    50,
    '�Felicidades! Has dado tus primeros pasos en tu viaje de aprendizaje.',
    'Completa cualquier ejercicio de comprensi�n lectora para desbloquear este logro.',
    ARRAY[
        'Lee el texto con atenci�n antes de responder',
        'No tengas miedo de equivocarte, es parte del aprendizaje'
    ],
    jsonb_build_object(
        'achievement_tier', 'starter',
        'demo_achievement', true,
        'module_required', null
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 2. Lector Principiante
(
    '90000001-0000-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Lector Principiante',
    'Completa 10 ejercicios de comprensi�n lectora',
    '=�',
    'progress'::gamification_system.achievement_category,
    'common',
    'elementary'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exercise_completion',
        'requirements', jsonb_build_object(
            'exercises_completed', 10
        )
    ),
    jsonb_build_object(
        'xp', 100,
        'ml_coins', 25,
        'badge', 'beginner_reader'
    ),
    25,
    false,
    true,
    false,
    2,
    100,
    '�Excelente! Ya eres un lector principiante. �Sigue as�!',
    'Completa 10 ejercicios de comprensi�n lectora en cualquier m�dulo.',
    ARRAY[
        'Practica diferentes tipos de textos',
        'Lee con atenci�n los detalles'
    ],
    jsonb_build_object(
        'achievement_tier', 'bronze',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 3. Lector Experimentado
(
    '90000001-0000-0000-0000-000000000003'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Lector Experimentado',
    'Completa 50 ejercicios de comprensi�n lectora',
    '=�',
    'progress'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exercise_completion',
        'requirements', jsonb_build_object(
            'exercises_completed', 50
        )
    ),
    jsonb_build_object(
        'xp', 250,
        'ml_coins', 75,
        'badge', 'experienced_reader'
    ),
    75,
    false,
    true,
    false,
    3,
    250,
    '�Impresionante! Tu experiencia como lector est� creciendo enormemente.',
    'Completa 50 ejercicios de comprensi�n lectora.',
    ARRAY[
        'Var�a los tipos de ejercicios',
        'Intenta ejercicios m�s dif�ciles'
    ],
    jsonb_build_object(
        'achievement_tier', 'silver',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 4. Lector Experto
(
    '90000001-0000-0000-0000-000000000004'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Lector Experto',
    'Completa 100 ejercicios de comprensi�n lectora',
    '<�',
    'progress'::gamification_system.achievement_category,
    'epic',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exercise_completion',
        'requirements', jsonb_build_object(
            'exercises_completed', 100
        )
    ),
    jsonb_build_object(
        'xp', 500,
        'ml_coins', 150,
        'badge', 'expert_reader'
    ),
    150,
    false,
    true,
    false,
    4,
    500,
    '�Extraordinario! Has alcanzado el nivel de lector experto.',
    'Completa 100 ejercicios de comprensi�n lectora.',
    ARRAY[
        'Mant�n tu constancia',
        'Ayuda a otros estudiantes'
    ],
    jsonb_build_object(
        'achievement_tier', 'gold',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 5. Maestro de la Lectura
(
    '90000001-0000-0000-0000-000000000005'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Maestro de la Lectura',
    'Completa 200 ejercicios de comprensi�n lectora',
    '=Q',
    'progress'::gamification_system.achievement_category,
    'legendary',
    'proficient'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exercise_completion',
        'requirements', jsonb_build_object(
            'exercises_completed', 200
        )
    ),
    jsonb_build_object(
        'xp', 1000,
        'ml_coins', 300,
        'badge', 'reading_master'
    ),
    300,
    false,
    true,
    false,
    5,
    1000,
    '�LEGENDARIO! Te has convertido en un verdadero Maestro de la Lectura.',
    'Completa 200 ejercicios de comprensi�n lectora.',
    ARRAY[
        'Eres un ejemplo para todos',
        'Tu dedicaci�n es inspiradora'
    ],
    jsonb_build_object(
        'achievement_tier', 'legendary',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: STREAK (3 achievements)
-- =====================================================

-- 6. Racha de 3 D�as
(
    '90000002-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Racha de 3 D�as',
    'Mant�n una racha de 3 d�as consecutivos practicando',
    '=%',
    'streak'::gamification_system.achievement_category,
    'common',
    'elementary'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'streak',
        'requirements', jsonb_build_object(
            'consecutive_days', 3
        )
    ),
    jsonb_build_object(
        'xp', 75,
        'ml_coins', 20,
        'badge', 'streak_3'
    ),
    20,
    false,
    true,
    false,
    10,
    75,
    '�Genial! Has mantenido tu racha por 3 d�as. �La constancia es clave!',
    'Practica al menos un ejercicio durante 3 d�as consecutivos.',
    ARRAY[
        'Establece un horario diario para practicar',
        'Aunque sea un ejercicio corto, mant�n la racha'
    ],
    jsonb_build_object(
        'streak_milestone', 3,
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 7. Racha de 7 D�as
(
    '90000002-0000-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Racha de 7 D�as',
    'Mant�n una racha de 7 d�as consecutivos practicando',
    '=%=%',
    'streak'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'streak',
        'requirements', jsonb_build_object(
            'consecutive_days', 7
        )
    ),
    jsonb_build_object(
        'xp', 150,
        'ml_coins', 50,
        'badge', 'streak_7'
    ),
    50,
    false,
    true,
    false,
    11,
    150,
    '�Incre�ble! Una semana completa de pr�ctica. �Tu dedicaci�n es admirable!',
    'Practica al menos un ejercicio durante 7 d�as consecutivos.',
    ARRAY[
        'Ya has creado un h�bito s�lido',
        'Sigue as� para alcanzar rachas m�s largas'
    ],
    jsonb_build_object(
        'streak_milestone', 7,
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 8. Racha de 30 D�as
(
    '90000002-0000-0000-0000-000000000003'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Racha de 30 D�as',
    'Mant�n una racha de 30 d�as consecutivos practicando',
    '=%=%=%',
    'streak'::gamification_system.achievement_category,
    'epic',
    'proficient'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'streak',
        'requirements', jsonb_build_object(
            'consecutive_days', 30
        )
    ),
    jsonb_build_object(
        'xp', 500,
        'ml_coins', 200,
        'badge', 'streak_30'
    ),
    200,
    false,
    true,
    false,
    12,
    500,
    '��PICO! 30 d�as de racha. Tu compromiso con el aprendizaje es extraordinario.',
    'Practica al menos un ejercicio durante 30 d�as consecutivos.',
    ARRAY[
        'Has desarrollado un h�bito excepcional',
        'Eres un modelo de constancia'
    ],
    jsonb_build_object(
        'streak_milestone', 30,
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: COMPLETION (4 achievements)
-- =====================================================

-- 9. M�dulo 1 Completado
(
    '90000003-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Comprensi�n Literal Dominada',
    'Completa todos los ejercicios del M�dulo 1: Comprensi�n Literal',
    '',
    'completion'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'module_completion',
        'requirements', jsonb_build_object(
            'module_id', 'modulo-01-comprension-literal',
            'completion_percentage', 100
        )
    ),
    jsonb_build_object(
        'xp', 200,
        'ml_coins', 100,
        'badge', 'module_1_complete'
    ),
    100,
    false,
    true,
    false,
    20,
    200,
    '�Felicidades! Has dominado la Comprensi�n Literal. �Sigue adelante!',
    'Completa todos los ejercicios del M�dulo 1 con al menos 60% de aciertos.',
    ARRAY[
        'Identifica informaci�n expl�cita en los textos',
        'Presta atenci�n a los detalles'
    ],
    jsonb_build_object(
        'module', 'M�DULO 1: Comprensi�n Literal',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 10. M�dulo 2 Completado
(
    '90000003-0000-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Comprensi�n Inferencial Dominada',
    'Completa todos los ejercicios del M�dulo 2: Comprensi�n Inferencial',
    '',
    'completion'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'module_completion',
        'requirements', jsonb_build_object(
            'module_id', 'modulo-02-comprension-inferencial',
            'completion_percentage', 100
        )
    ),
    jsonb_build_object(
        'xp', 250,
        'ml_coins', 125,
        'badge', 'module_2_complete'
    ),
    125,
    false,
    true,
    false,
    21,
    250,
    '�Excelente! Has dominado la Comprensi�n Inferencial. Tu habilidad crece.',
    'Completa todos los ejercicios del M�dulo 2 con al menos 60% de aciertos.',
    ARRAY[
        'Lee entre l�neas para encontrar significados impl�citos',
        'Usa tu conocimiento previo para hacer inferencias'
    ],
    jsonb_build_object(
        'module', 'M�DULO 2: Comprensi�n Inferencial',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 11. M�dulo 3 Completado
(
    '90000003-0000-0000-0000-000000000003'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Comprensi�n Cr�tica Dominada',
    'Completa todos los ejercicios del M�dulo 3: Comprensi�n Cr�tica',
    '',
    'completion'::gamification_system.achievement_category,
    'epic',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'module_completion',
        'requirements', jsonb_build_object(
            'module_id', 'modulo-03-comprension-critica',
            'completion_percentage', 100
        )
    ),
    jsonb_build_object(
        'xp', 300,
        'ml_coins', 150,
        'badge', 'module_3_complete'
    ),
    150,
    false,
    true,
    false,
    22,
    300,
    '�Impresionante! Has dominado la Comprensi�n Cr�tica. Tu pensamiento es agudo.',
    'Completa todos los ejercicios del M�dulo 3 con al menos 60% de aciertos.',
    ARRAY[
        'Eval�a la calidad y veracidad de la informaci�n',
        'Desarrolla tu pensamiento cr�tico'
    ],
    jsonb_build_object(
        'module', 'M�DULO 3: Comprensi�n Cr�tica',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 12. Todos los M�dulos Completados
(
    '90000003-0000-0000-0000-000000000004'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Completista Total',
    'Completa todos los m�dulos del sistema',
    '<�',
    'completion'::gamification_system.achievement_category,
    'legendary',
    'proficient'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'all_modules_completion',
        'requirements', jsonb_build_object(
            'modules_completed', 5,
            'min_score_average', 70
        )
    ),
    jsonb_build_object(
        'xp', 1000,
        'ml_coins', 500,
        'badge', 'completionist'
    ),
    500,
    false,
    true,
    false,
    23,
    1000,
    '�LEGENDARIO! Has completado todos los m�dulos. Eres un verdadero completista.',
    'Completa los 5 m�dulos del sistema con promedio de 70% o superior.',
    ARRAY[
        'Tu dedicaci�n es ejemplar',
        'Has alcanzado el nivel m�s alto'
    ],
    jsonb_build_object(
        'achievement_tier', 'ultimate',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: MASTERY (3 achievements)
-- =====================================================

-- 13. Perfeccionista
(
    '90000004-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Perfeccionista',
    'Obt�n 100% de aciertos en 10 ejercicios',
    'P',
    'mastery'::gamification_system.achievement_category,
    'rare',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'perfect_score',
        'requirements', jsonb_build_object(
            'perfect_exercises', 10,
            'score_required', 100
        )
    ),
    jsonb_build_object(
        'xp', 300,
        'ml_coins', 150,
        'badge', 'perfectionist'
    ),
    150,
    false,
    true,
    false,
    30,
    300,
    '�Perfecto! Tu precisi�n es admirable. 10 ejercicios perfectos.',
    'Obt�n 100% de aciertos en 10 ejercicios diferentes.',
    ARRAY[
        'Lee cuidadosamente antes de responder',
        'Revisa tus respuestas antes de enviar'
    ],
    jsonb_build_object(
        'mastery_type', 'perfect_score',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 14. Experto en Inferencias
(
    '90000004-0000-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Experto en Inferencias',
    'Completa 20 ejercicios de inferencia con 90% o m�s de aciertos',
    '>�',
    'mastery'::gamification_system.achievement_category,
    'epic',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'skill_mastery',
        'requirements', jsonb_build_object(
            'skill_type', 'inferencial',
            'exercises_completed', 20,
            'min_score', 90
        )
    ),
    jsonb_build_object(
        'xp', 400,
        'ml_coins', 200,
        'badge', 'inference_expert'
    ),
    200,
    false,
    true,
    false,
    31,
    400,
    '�Extraordinario! Eres un experto en hacer inferencias. Tu comprensi�n es profunda.',
    'Completa 20 ejercicios de comprensi�n inferencial con 90% o m�s.',
    ARRAY[
        'Conecta la informaci�n del texto con tu conocimiento',
        'Busca pistas en el contexto'
    ],
    jsonb_build_object(
        'mastery_type', 'skill_expert',
        'skill', 'inferencial',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 15. Cr�tico Avanzado
(
    '90000004-0000-0000-0000-000000000003'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Cr�tico Avanzado',
    'Completa 20 ejercicios de pensamiento cr�tico con 90% o m�s',
    '<�',
    'mastery'::gamification_system.achievement_category,
    'epic',
    'proficient'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'skill_mastery',
        'requirements', jsonb_build_object(
            'skill_type', 'critico',
            'exercises_completed', 20,
            'min_score', 90
        )
    ),
    jsonb_build_object(
        'xp', 500,
        'ml_coins', 250,
        'badge', 'critical_thinker'
    ),
    250,
    false,
    true,
    false,
    32,
    500,
    '��PICO! Tu pensamiento cr�tico es de nivel avanzado. Sobresaliente.',
    'Completa 20 ejercicios de comprensi�n cr�tica con 90% o m�s.',
    ARRAY[
        'Eval�a argumentos y evidencias',
        'Cuestiona y analiza la informaci�n'
    ],
    jsonb_build_object(
        'mastery_type', 'skill_expert',
        'skill', 'critico',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: EXPLORATION (2 achievements)
-- =====================================================

-- 16. Explorador Curioso
(
    '90000005-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Explorador Curioso',
    'Explora al menos 3 m�dulos diferentes',
    '=
',
    'exploration'::gamification_system.achievement_category,
    'common',
    'elementary'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exploration',
        'requirements', jsonb_build_object(
            'different_modules', 3,
            'min_exercises_per_module', 1
        )
    ),
    jsonb_build_object(
        'xp', 100,
        'ml_coins', 50,
        'badge', 'curious_explorer'
    ),
    50,
    false,
    true,
    false,
    40,
    100,
    '�Genial! Tu curiosidad te ha llevado a explorar diferentes m�dulos.',
    'Completa al menos un ejercicio en 3 m�dulos diferentes.',
    ARRAY[
        'Var�a tus actividades de aprendizaje',
        'Descubre nuevos tipos de textos'
    ],
    jsonb_build_object(
        'exploration_type', 'module_variety',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 17. Aventurero del Conocimiento
(
    '90000005-0000-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Aventurero del Conocimiento',
    'Completa ejercicios de todos los niveles de dificultad',
    '=�',
    'exploration'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exploration',
        'requirements', jsonb_build_object(
            'difficulty_levels', jsonb_build_array('beginner', 'elementary', 'pre_intermediate', 'upper_intermediate'),
            'min_exercises_per_level', 2
        )
    ),
    jsonb_build_object(
        'xp', 200,
        'ml_coins', 100,
        'badge', 'knowledge_adventurer'
    ),
    100,
    false,
    true,
    false,
    41,
    200,
    '�Incre�ble! Has explorado todos los niveles de dificultad. Eres un verdadero aventurero.',
    'Completa al menos 2 ejercicios de cada nivel de dificultad.',
    ARRAY[
        'Reta tus l�mites con ejercicios dif�ciles',
        'La variedad enriquece tu aprendizaje'
    ],
    jsonb_build_object(
        'exploration_type', 'difficulty_variety',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: SOCIAL (2 achievements)
-- =====================================================

-- 18. Compa�ero de Aula
(
    '90000006-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Compa�ero de Aula',
    '�nete a tu primera aula virtual',
    '=e',
    'social'::gamification_system.achievement_category,
    'common',
    'beginner'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'social',
        'requirements', jsonb_build_object(
            'classrooms_joined', 1
        )
    ),
    jsonb_build_object(
        'xp', 50,
        'ml_coins', 25,
        'badge', 'classroom_member'
    ),
    25,
    false,
    true,
    false,
    50,
    50,
    '�Bienvenido! Te has unido a tu primera aula. El aprendizaje colaborativo comienza.',
    '�nete a un aula virtual para desbloquear este logro.',
    ARRAY[
        'Colabora con tus compa�eros',
        'Aprende de las experiencias de otros'
    ],
    jsonb_build_object(
        'social_type', 'classroom_join',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 19. Estudiante Colaborativo
(
    '90000006-0000-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Estudiante Colaborativo',
    'Participa en 5 actividades sociales (aulas, desaf�os, etc.)',
    '>',
    'social'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'social',
        'requirements', jsonb_build_object(
            'social_activities', 5
        )
    ),
    jsonb_build_object(
        'xp', 150,
        'ml_coins', 75,
        'badge', 'collaborative_student'
    ),
    75,
    false,
    true,
    false,
    51,
    150,
    '�Excelente! Tu participaci�n social es notable. Sigues creciendo con otros.',
    'Participa en 5 actividades sociales (unirte a aulas, aceptar desaf�os, etc.).',
    ARRAY[
        'El aprendizaje es m�s rico cuando es social',
        'Comparte tus logros con otros'
    ],
    jsonb_build_object(
        'social_type', 'social_participation',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: SPECIAL (1 achievement)
-- =====================================================

-- 20. Primera Visita
(
    '90000007-0000-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Primera Visita',
    'Inicia sesi�n por primera vez en GAMILIT',
    '<�',
    'special'::gamification_system.achievement_category,
    'common',
    'beginner'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'special',
        'requirements', jsonb_build_object(
            'first_login', true
        )
    ),
    jsonb_build_object(
        'xp', 25,
        'ml_coins', 10,
        'badge', 'first_visit'
    ),
    10,
    false,
    true,
    false,
    60,
    25,
    '�Bienvenido a GAMILIT! Este es el comienzo de tu aventura de aprendizaje.',
    'Este logro se desbloquea autom�ticamente al iniciar sesi�n por primera vez.',
    ARRAY[
        'Explora la plataforma',
        'Comienza con ejercicios f�ciles'
    ],
    jsonb_build_object(
        'special_type', 'welcome',
        'demo_achievement', true,
        'auto_unlock', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- NUEVOS ACHIEVEMENTS - TIENDA Y ENGAGEMENT (10 adicionales)
-- Agregados: 2025-11-29
-- =====================================================

-- =====================================================
-- CATEGORY: SOCIAL (3 nuevos - shop y engagement)
-- =====================================================

-- 21. Primera Compra
(
    '90000008-0001-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Primera Compra',
    'Realiza tu primera compra en la tienda virtual',
    '🛒',
    'social'::gamification_system.achievement_category,
    'common',
    'beginner'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'shop_purchase',
        'requirements', jsonb_build_object(
            'purchases_count', 1
        )
    ),
    jsonb_build_object(
        'xp', 50,
        'ml_coins', 25,
        'badge', 'first_purchase'
    ),
    25,
    false,
    true,
    false,
    52,
    50,
    '¡Felicidades! Has hecho tu primera compra en la tienda GAMILIT.',
    'Compra cualquier item en la tienda virtual.',
    ARRAY[
        'Los ML Coins se ganan completando ejercicios',
        'Explora diferentes categorías de items'
    ],
    jsonb_build_object(
        'social_type', 'shop_engagement',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 22. Coleccionista Novato
(
    '90000008-0001-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Coleccionista Novato',
    'Adquiere 5 items diferentes de la tienda',
    '📦',
    'social'::gamification_system.achievement_category,
    'rare',
    'elementary'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'collection',
        'requirements', jsonb_build_object(
            'unique_items', 5
        )
    ),
    jsonb_build_object(
        'xp', 150,
        'ml_coins', 75,
        'badge', 'novice_collector'
    ),
    75,
    false,
    true,
    false,
    53,
    150,
    '¡Excelente! Estás comenzando una colección interesante.',
    'Compra 5 items diferentes en la tienda.',
    ARRAY[
        'Varía entre categorías de items',
        'Busca items que complementen tu estilo'
    ],
    jsonb_build_object(
        'social_type', 'collection',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 23. Comunicador Social
(
    '90000008-0001-0000-0000-000000000003'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Comunicador Social',
    'Usa 10 stickers o emojis en conversaciones',
    '💬',
    'social'::gamification_system.achievement_category,
    'common',
    'beginner'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'social',
        'requirements', jsonb_build_object(
            'stickers_used', 10
        )
    ),
    jsonb_build_object(
        'xp', 75,
        'ml_coins', 30,
        'badge', 'social_communicator'
    ),
    30,
    false,
    true,
    false,
    54,
    75,
    '¡Genial! Te comunicas activamente con la comunidad GAMILIT.',
    'Usa 10 stickers o emojis en chats o comentarios.',
    ARRAY[
        'Los emojis enriquecen la comunicación',
        'Expresa tus emociones de forma creativa'
    ],
    jsonb_build_object(
        'social_type', 'communication',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: STREAK (1 nuevo)
-- =====================================================

-- 24. Racha de Fuego
(
    '90000008-0002-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Racha de Fuego',
    'Mantén una racha de 14 días consecutivos practicando',
    '🔥',
    'streak'::gamification_system.achievement_category,
    'epic',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'streak',
        'requirements', jsonb_build_object(
            'consecutive_days', 14
        )
    ),
    jsonb_build_object(
        'xp', 300,
        'ml_coins', 100,
        'badge', 'streak_14'
    ),
    100,
    false,
    true,
    false,
    13,
    300,
    '¡Épico! Dos semanas de racha sin parar. Tu dedicación es extraordinaria.',
    'Practica al menos un ejercicio durante 14 días consecutivos.',
    ARRAY[
        'Estás cerca del hábito de 21 días',
        'Tu constancia es inspiradora'
    ],
    jsonb_build_object(
        'streak_milestone', 14,
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: MASTERY (2 nuevos)
-- =====================================================

-- 25. Velocista Lector
(
    '90000008-0003-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Velocista Lector',
    'Completa un ejercicio en menos de 2 minutos con 100% de aciertos',
    '⚡',
    'mastery'::gamification_system.achievement_category,
    'rare',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'speed_mastery',
        'requirements', jsonb_build_object(
            'max_time_seconds', 120,
            'min_score', 100
        )
    ),
    jsonb_build_object(
        'xp', 200,
        'ml_coins', 100,
        'badge', 'speed_reader'
    ),
    100,
    false,
    true,
    false,
    33,
    200,
    '¡Impresionante! Velocidad y precisión combinadas perfectamente.',
    'Completa un ejercicio en menos de 2 minutos con puntaje perfecto.',
    ARRAY[
        'La práctica mejora tu velocidad de lectura',
        'Lee rápido pero sin sacrificar comprensión'
    ],
    jsonb_build_object(
        'mastery_type', 'speed',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 26. Perfeccionista Total
(
    '90000008-0003-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Perfeccionista Total',
    'Obtén 100% de aciertos en 10 ejercicios consecutivos',
    '🎯',
    'mastery'::gamification_system.achievement_category,
    'legendary',
    'proficient'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'perfect_streak',
        'requirements', jsonb_build_object(
            'perfect_exercises_consecutive', 10,
            'score_required', 100
        )
    ),
    jsonb_build_object(
        'xp', 750,
        'ml_coins', 300,
        'badge', 'total_perfectionist'
    ),
    300,
    false,
    true,
    false,
    34,
    750,
    '¡LEGENDARIO! 10 ejercicios perfectos seguidos. Tu maestría es absoluta.',
    'Obtén 100% de aciertos en 10 ejercicios consecutivos.',
    ARRAY[
        'Mantén la concentración en cada ejercicio',
        'Tu consistencia es excepcional'
    ],
    jsonb_build_object(
        'mastery_type', 'perfect_streak',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: EXPLORATION (1 nuevo)
-- =====================================================

-- 27. Explorador Completo
(
    '90000008-0004-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Explorador Completo',
    'Visita todas las secciones de la plataforma GAMILIT',
    '🗺️',
    'exploration'::gamification_system.achievement_category,
    'legendary',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'exploration',
        'requirements', jsonb_build_object(
            'sections_visited', jsonb_build_array('modules', 'shop', 'leaderboard', 'profile', 'guild', 'achievements')
        )
    ),
    jsonb_build_object(
        'xp', 500,
        'ml_coins', 200,
        'badge', 'complete_explorer'
    ),
    200,
    false,
    true,
    false,
    42,
    500,
    '¡Legendario! Has explorado cada rincón de GAMILIT. Conoces la plataforma completa.',
    'Visita todas las secciones principales: módulos, tienda, leaderboard, perfil, gremio y logros.',
    ARRAY[
        'Cada sección tiene características únicas',
        'Conocer la plataforma maximiza tu experiencia'
    ],
    jsonb_build_object(
        'exploration_type', 'complete_platform',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: SPECIAL (2 nuevos - gremio y shop)
-- =====================================================

-- 28. Mecenas del Gremio
(
    '90000008-0005-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Mecenas del Gremio',
    'Compra 5 items de categoría Gremio en la tienda',
    '👑',
    'special'::gamification_system.achievement_category,
    'epic',
    'pre_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'shop_category',
        'requirements', jsonb_build_object(
            'category', 'guild',
            'items_purchased', 5
        )
    ),
    jsonb_build_object(
        'xp', 300,
        'ml_coins', 150,
        'badge', 'guild_patron'
    ),
    150,
    false,
    true,
    false,
    61,
    300,
    '¡Épico! Tu gremio luce increíble gracias a tu inversión.',
    'Compra 5 items diferentes de la categoría Gremio.',
    ARRAY[
        'Los items de gremio mejoran el prestigio colectivo',
        'Contribuye al éxito de tu equipo'
    ],
    jsonb_build_object(
        'special_type', 'guild_shop',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- 29. Fashionista
(
    '90000008-0005-0000-0000-000000000002'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Fashionista',
    'Equipa 3 cosméticos diferentes al mismo tiempo',
    '✨',
    'special'::gamification_system.achievement_category,
    'rare',
    'elementary'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'cosmetics_equipped',
        'requirements', jsonb_build_object(
            'equipped_cosmetics', 3
        )
    ),
    jsonb_build_object(
        'xp', 100,
        'ml_coins', 50,
        'badge', 'fashionista'
    ),
    50,
    false,
    true,
    false,
    62,
    100,
    '¡Genial! Tu estilo es único y llamativo.',
    'Equipa 3 cosméticos simultáneamente (avatar, marco, fondo).',
    ARRAY[
        'Combina cosméticos para crear tu estilo',
        'La personalización te hace destacar'
    ],
    jsonb_build_object(
        'special_type', 'cosmetics_style',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
),

-- =====================================================
-- CATEGORY: COMPLETION (1 nuevo - coleccionista)
-- =====================================================

-- 30. Coleccionista Experto
(
    '90000008-0006-0000-0000-000000000001'::uuid,
    'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid,
    'Coleccionista Experto',
    'Adquiere 20 items diferentes de la tienda',
    '🏆',
    'completion'::gamification_system.achievement_category,
    'epic',
    'upper_intermediate'::educational_content.difficulty_level,
    jsonb_build_object(
        'type', 'collection',
        'requirements', jsonb_build_object(
            'unique_items', 20
        )
    ),
    jsonb_build_object(
        'xp', 400,
        'ml_coins', 200,
        'badge', 'expert_collector'
    ),
    200,
    false,
    true,
    false,
    24,
    400,
    '¡Épico! Tu colección es impresionante y variada.',
    'Compra 20 items diferentes en la tienda.',
    ARRAY[
        'Explora todas las categorías de la tienda',
        'Una colección completa demuestra dedicación'
    ],
    jsonb_build_object(
        'achievement_tier', 'collector',
        'demo_achievement', true
    ),
    gamilit.now_mexico(),
    gamilit.now_mexico()
)

ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    description = EXCLUDED.description,
    icon = EXCLUDED.icon,
    category = EXCLUDED.category,
    rarity = EXCLUDED.rarity,
    difficulty_level = EXCLUDED.difficulty_level,
    conditions = EXCLUDED.conditions,
    rewards = EXCLUDED.rewards,
    ml_coins_reward = EXCLUDED.ml_coins_reward,
    is_secret = EXCLUDED.is_secret,
    is_active = EXCLUDED.is_active,
    is_repeatable = EXCLUDED.is_repeatable,
    order_index = EXCLUDED.order_index,
    points_value = EXCLUDED.points_value,
    unlock_message = EXCLUDED.unlock_message,
    instructions = EXCLUDED.instructions,
    tips = EXCLUDED.tips,
    metadata = EXCLUDED.metadata,
    updated_at = gamilit.now_mexico();

-- =====================================================
-- Verification Query
-- =====================================================

DO $$
DECLARE
    achievement_count INTEGER;
    progress_count INTEGER;
    streak_count INTEGER;
    completion_count INTEGER;
    mastery_count INTEGER;
    exploration_count INTEGER;
    social_count INTEGER;
    special_count INTEGER;
BEGIN
    SELECT COUNT(*) INTO achievement_count
    FROM gamification_system.achievements
    WHERE metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO progress_count
    FROM gamification_system.achievements
    WHERE category = 'progress' AND metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO streak_count
    FROM gamification_system.achievements
    WHERE category = 'streak' AND metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO completion_count
    FROM gamification_system.achievements
    WHERE category = 'completion' AND metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO mastery_count
    FROM gamification_system.achievements
    WHERE category = 'mastery' AND metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO exploration_count
    FROM gamification_system.achievements
    WHERE category = 'exploration' AND metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO social_count
    FROM gamification_system.achievements
    WHERE category = 'social' AND metadata->>'demo_achievement' = 'true';

    SELECT COUNT(*) INTO special_count
    FROM gamification_system.achievements
    WHERE category = 'special' AND metadata->>'demo_achievement' = 'true';

    RAISE NOTICE '========================================';
    RAISE NOTICE 'ACHIEVEMENTS DEMO CREADOS EXITOSAMENTE';
    RAISE NOTICE '========================================';
    RAISE NOTICE 'Total achievements: %', achievement_count;
    RAISE NOTICE '  - Progress: %', progress_count;
    RAISE NOTICE '  - Streak: %', streak_count;
    RAISE NOTICE '  - Completion: %', completion_count;
    RAISE NOTICE '  - Mastery: %', mastery_count;
    RAISE NOTICE '  - Exploration: %', exploration_count;
    RAISE NOTICE '  - Social: %', social_count;
    RAISE NOTICE '  - Special: %', special_count;
    RAISE NOTICE '========================================';

    IF achievement_count = 30 THEN
        RAISE NOTICE ' Todos los achievements demo fueron creados correctamente';
    ELSE
        RAISE WARNING '� Se esperaban 30 achievements, se crearon %', achievement_count;
    END IF;
END $$;

-- =====================================================
-- Listado de achievements por categor�a
-- =====================================================

DO $$
DECLARE
    achievement_record RECORD;
    current_category TEXT := '';
BEGIN
    RAISE NOTICE '';
    RAISE NOTICE 'Listado de achievements demo:';
    RAISE NOTICE '========================================';

    FOR achievement_record IN
        SELECT
            name,
            category,
            rarity,
            difficulty_level,
            points_value,
            ml_coins_reward
        FROM gamification_system.achievements
        WHERE metadata->>'demo_achievement' = 'true'
        ORDER BY category, order_index
    LOOP
        IF current_category != achievement_record.category THEN
            current_category := achievement_record.category;
            RAISE NOTICE '';
            RAISE NOTICE '=== % ===', UPPER(current_category);
        END IF;

        RAISE NOTICE '  - % [%/%]',
            achievement_record.name,
            achievement_record.rarity,
            achievement_record.difficulty_level;
        RAISE NOTICE '    Puntos: % | ML Coins: %',
            achievement_record.points_value,
            achievement_record.ml_coins_reward;
    END LOOP;

    RAISE NOTICE '';
    RAISE NOTICE '========================================';
END $$;
