<?php

if (!defined('ABSPATH')) {
    exit;
}

class List2Play_Servers_Activator {
    
    /**
     * Plugin activation
     */
    public static function activate() {
        // Set default options if they don't exist
        if (get_option('list2play_api_base_url') === false) {
            add_option('list2play_api_base_url', 'https://list2play.net/api');
        }
        
        if (get_option('list2play_cache_duration') === false) {
            add_option('list2play_cache_duration', 300);
        }
        
        if (get_option('list2play_default_per_page') === false) {
            add_option('list2play_default_per_page', 20);
        }
        if (get_option('list2play_default_style_preset') === false) {
            add_option('list2play_default_style_preset', 'default');
        }
        
        // Set default display options
        $display_options = [
            'list2play_show_hostname' => '1',
            'list2play_show_status' => '1',
            'list2play_show_address' => '1',
            'list2play_show_game' => '1',
            'list2play_show_region' => '1',
            'list2play_show_players' => '1',
            'list2play_show_map' => '1',
            'list2play_show_votes' => '1',
            'list2play_show_chart' => '0',
        ];
        
        foreach ($display_options as $option => $default) {
            if (get_option($option) === false) {
                add_option($option, $default);
            }
        }
        
        // Flush rewrite rules if needed
        flush_rewrite_rules();
        
        // Set default for metadata sending (enabled by default, user can disable)
        if (get_option('list2play_send_metadata') === false) {
            add_option('list2play_send_metadata', '1');
        }
        
        // Send client metadata to API for statistics (optional, non-blocking, respects user setting)
        $api = new List2Play_Servers_API();
        $api->send_client_metadata();
    }
}

