//! Preset configurations
//!
//! **Note**: This module is kept for backward compatibility.
//! For new projects, use the Topaz template system instead:
//! - `global_topaz_templates()` for built-in templates
//! - `TopazTemplateManager` for custom template management
//! - See `docs/TEMPLATES.md` for detailed documentation

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::video::{VideoUpscaleParams, InterpolationParams};
use crate::image::ImageUpscaleParams;

/// Video processing preset
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VideoPreset {
    pub name: String,
    pub description: String,
    pub upscale: Option<VideoUpscaleParams>,
    pub interpolation: Option<InterpolationParams>,
}

/// Image processing preset
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImagePreset {
    pub name: String,
    pub description: String,
    pub params: ImageUpscaleParams,
}

/// Preset manager for video and image processing
#[derive(Debug, Clone)]
pub struct PresetManager {
    video_presets: HashMap<String, VideoPreset>,
    image_presets: HashMap<String, ImagePreset>,
}

impl Default for PresetManager {
    fn default() -> Self {
        Self {
            video_presets: HashMap::new(),
            image_presets: HashMap::new(),
        }
    }
}

impl PresetManager {
    /// Create a new preset manager
    pub fn new() -> Self {
        Self::default()
    }

    /// Load default presets (now empty - use Topaz templates instead)
    pub fn load_default_presets(&mut self) {
        // Default presets have been moved to the Topaz template system
        // Use global_topaz_templates() for built-in templates
    }

    /// Get video preset by name
    pub fn get_video_preset(&self, name: &str) -> Option<&VideoPreset> {
        self.video_presets.get(name)
    }

    /// Get image preset by name
    pub fn get_image_preset(&self, name: &str) -> Option<&ImagePreset> {
        self.image_presets.get(name)
    }

    /// List all video preset names
    pub fn list_video_presets(&self) -> Vec<String> {
        self.video_presets.keys().cloned().collect()
    }

    /// List all image preset names
    pub fn list_image_presets(&self) -> Vec<String> {
        self.image_presets.keys().cloned().collect()
    }

    /// Add custom video preset
    pub fn add_video_preset(&mut self, name: String, preset: VideoPreset) {
        self.video_presets.insert(name, preset);
    }

    /// Add custom image preset
    pub fn add_image_preset(&mut self, name: String, preset: ImagePreset) {
        self.image_presets.insert(name, preset);
    }

    /// Remove video preset
    pub fn remove_video_preset(&mut self, name: &str) -> Option<VideoPreset> {
        self.video_presets.remove(name)
    }

    /// Remove image preset
    pub fn remove_image_preset(&mut self, name: &str) -> Option<ImagePreset> {
        self.image_presets.remove(name)
    }
}

/// Global preset manager instance
static GLOBAL_PRESETS: std::sync::OnceLock<std::sync::Mutex<PresetManager>> = std::sync::OnceLock::new();

/// Get global preset manager
pub fn global_presets() -> &'static std::sync::Mutex<PresetManager> {
    GLOBAL_PRESETS.get_or_init(|| std::sync::Mutex::new(PresetManager::new()))
}
