-- Ajouter des stats de test pour admin@cel.cm

-- Trouver l'ID du profil admin
DO $$
DECLARE
    admin_profile_id TEXT;
    match_id_1 TEXT := gen_random_uuid()::text;
    match_id_2 TEXT := gen_random_uuid()::text;
    match_id_3 TEXT := gen_random_uuid()::text;
    club_id TEXT;
    league_id TEXT;
BEGIN
    -- Get admin profile ID
    SELECT up.id INTO admin_profile_id 
    FROM "UserProfile" up
    JOIN "User" u ON u.id = up."userId"
    WHERE u.email = 'admin@cel.cm'
    LIMIT 1;

    -- Get club and league IDs
    SELECT id INTO club_id FROM "Club" LIMIT 1;
    SELECT id INTO league_id FROM "League" LIMIT 1;

    -- Create 3 test matches
    INSERT INTO "Match" (id, "leagueId", "homeClubId", "awayClubId", "homeScore", "awayScore", "scheduledAt", "createdAt")
    VALUES 
        (match_id_1, league_id, club_id, club_id, 3, 1, NOW() - INTERVAL '7 days', NOW()),
        (match_id_2, league_id, club_id, club_id, 2, 2, NOW() - INTERVAL '5 days', NOW()),
        (match_id_3, league_id, club_id, club_id, 1, 2, NOW() - INTERVAL '3 days', NOW());

    -- Add player stats for admin
    INSERT INTO "MatchPlayerStat" (id, "matchId", "playerProfileId", "clubSide", "minutesPlayed", goals, assists, "yellowCards", "redCards", rating, "createdAt")
    VALUES 
        (gen_random_uuid()::text, match_id_1, admin_profile_id, club_id, 90, 2, 1, 0, 0, 8.5, NOW()),
        (gen_random_uuid()::text, match_id_2, admin_profile_id, club_id, 85, 1, 2, 1, 0, 7.8, NOW()),
        (gen_random_uuid()::text, match_id_3, admin_profile_id, club_id, 75, 0, 1, 0, 0, 7.2, NOW());

    RAISE NOTICE 'Stats de test créées avec succès pour admin@cel.cm';
END $$;
