-- Enhance settings table to support more structured configuration
ALTER TABLE settings
    ADD COLUMN category TEXT DEFAULT 'general';
ALTER TABLE settings
    ADD COLUMN user_id INTEGER DEFAULT 1;
ALTER TABLE settings
    ADD COLUMN updated_at TIMESTAMP DEFAULT (datetime('now'));

-- Create index for better performance
CREATE INDEX IF NOT EXISTS idx_settings_category ON settings (category);
CREATE INDEX IF NOT EXISTS idx_settings_user_id ON settings (user_id);

-- Insert default settings based on roadmap configuration
INSERT OR IGNORE INTO settings (key, val, category)
VALUES
-- Display settings
('default_view', 'compact', 'display'),
('articles_per_page', '50', 'display'),
('show_reading_time', '1', 'display'),
('show_word_count', '0', 'display'),
('highlight_unread', '1', 'display'),
('theme', 'auto', 'display'),

-- Analytics settings
('analytics_enabled', '1', 'analytics'),
('track_reading_time', '1', 'analytics'),
('track_scroll_position', '1', 'analytics'),
('retention_days', '365', 'analytics'),
('aggregate_older_data', '1', 'analytics'),

-- Filtering settings
('enable_smart_suggestions', '1', 'filtering'),
('max_recent_filters', '10', 'filtering'),
('auto_save_filters', '1', 'filtering'),
('default_sort', 'added_desc', 'filtering'),
('enable_geographic_hierarchy', '1', 'filtering'),
('auto_migrate_country_filters', '1', 'filtering'),

-- Sharing settings
('default_share_format', 'text', 'sharing'),
('include_summary', '1', 'sharing'),
('include_tags', '1', 'sharing'),
('include_source', '1', 'sharing'),
('copy_to_clipboard', '1', 'sharing'),

-- AI settings
('ai_enabled', '1', 'ai'),
('ai_provider', 'ollama', 'ai'),
('ai_timeout_seconds', '120', 'ai'),
('ai_summary_enabled', '1', 'ai'),
('ai_summary_temperature', '0.1', 'ai'),
('ai_summary_max_tokens', '1000', 'ai'),
('ai_tagging_enabled', '1', 'ai'),
('ai_tagging_temperature', '0.3', 'ai'),
('ai_tagging_max_tokens', '200', 'ai'),
('max_tags_per_article', '10', 'ai'),
('min_confidence_threshold', '0.7', 'ai'),
('enable_geographic_tagging', '1', 'ai'),
('enable_category_tagging', '1', 'ai'),
('geographic_hierarchy_levels', '3', 'ai'),

-- Scraping settings
('scraping_timeout_seconds', '30', 'scraping'),
('scraping_max_retries', '3', 'scraping'),
('max_content_length', '50000', 'scraping'),
('respect_robots_txt', '1', 'scraping'),
('rate_limit_delay_ms', '1000', 'scraping'),

-- Processing settings
('batch_size', '10', 'processing'),
('max_concurrent', '5', 'processing'),
('retry_attempts', '3', 'processing'),
('priority_manual', '1', 'processing'),
('auto_mark_read_on_view', '0', 'processing');
