import mysql.connector
from mysql.connector import Error

DB_CONFIG = {
    'host': 'officialsite.kr',
    'port': 23306,
    'user': 'admin',
    'password': 'dlgks~123',
    'database': 'app_master'
}

def update_badges():
    conn = None
    try:
        conn = mysql.connector.connect(**DB_CONFIG)
        cursor = conn.cursor()
        print("DB Connected")

        badges = [
            ('first_play', '첫 발걸음', '첫 게임 플레이', 'play_arrow', '0xFF4CAF50', 'total_plays', 1, 1),
            ('plays_10', '밸런스 입문자', '10번 플레이 달성', 'sports_esports', '0xFF2196F3', 'total_plays', 10, 2),
            ('plays_50', '밸런스 중급자', '50번 플레이 달성', 'military_tech', '0xFF9C27B0', 'total_plays', 50, 3),
            ('plays_100', '밸런스 마스터', '100번 플레이 달성', 'emoji_events', '0xFFFF9800', 'total_plays', 100, 4),
            ('streak_3', '3일 연속', '3일 연속 플레이', 'local_fire_department', '0xFFE91E63', 'streak', 3, 5),
            ('streak_5', '연속왕', '5일 연속 플레이', 'whatshot', '0xFFFF5722', 'streak', 5, 6),
            ('streak_7', '일주일 도전', '7일 연속 플레이', 'bolt', '0xFFF44336', 'streak', 7, 7),
            ('streak_30', '한 달 완주', '30일 연속 플레이', 'diamond', '0xFF673AB7', 'streak', 30, 8),
            ('speed_1', '스피드', '1초 안에 선택', 'flash_on', '0xFFFFEB3B', 'speed', 1, 9),
            ('speed_05', '번개손', '0.5초 안에 선택', 'offline_bolt', '0xFFFFC107', 'speed', 0.5, 10),
            ('creator_1', '크리에이터', '첫 게임 제작', 'create', '0xFF00BCD4', 'games_created', 1, 11),
            ('creator_5', '게임 메이커', '5개 게임 제작', 'construction', '0xFF009688', 'games_created', 5, 12),
            ('likes_10', '인기인', '좋아요 10개 획득', 'favorite', '0xFFE91E63', 'likes_received', 10, 13),
            ('likes_50', '스타', '좋아요 50개 획득', 'star', '0xFFFFD700', 'likes_received', 50, 14),
            ('likes_100', '슈퍼스타', '좋아요 100개 획득', 'auto_awesome', '0xFFFF4081', 'likes_received', 100, 15),
            ('all_difficulty', '정복자', '모든 난이도 클리어', 'workspace_premium', '0xFF7C4DFF', 'all_difficulty', 5, 16),
        ]

        for badge in badges:
            cursor.execute("""
                INSERT INTO balancepick_badges (id, name, description, icon_name, color, condition_type, condition_value, order_index)
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
                ON DUPLICATE KEY UPDATE
                    name = VALUES(name),
                    description = VALUES(description),
                    icon_name = VALUES(icon_name),
                    color = VALUES(color),
                    condition_type = VALUES(condition_type),
                    condition_value = VALUES(condition_value),
                    order_index = VALUES(order_index)
            """, badge)

        conn.commit()
        print(f"Updated {len(badges)} badges to Korean")
        print("=== Done ===")

    except Error as e:
        print(f"Error: {e}")
    finally:
        if conn and conn.is_connected():
            cursor.close()
            conn.close()

if __name__ == "__main__":
    update_badges()
