//! Lazy checkpoint loading system (Candle-free stub).
//!
//! The Candle-based `LazyCheckpointLoader` has been replaced by the safetensors
//! save/load functions in `crate::checkpoint`. This module retains the
//! `LoadStrategy` enum and `LazyCheckpointLoader` struct name for downstream
//! compatibility, but the implementation now delegates to the checkpoint module.

use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};

use crate::MLError;

/// Loading strategy for checkpoint components.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum LoadStrategy {
    /// Load all weights immediately (default).
    Eager,
    /// Load weights on first access.
    Lazy,
    /// Memory-mapped (not implemented — falls back to Eager).
    MemoryMapped,
}

/// Lazy checkpoint loader (Candle-free stub).
///
/// With Candle removed, checkpoint loading is handled by `crate::checkpoint`
/// using `GpuVarStore::import_from_host` and the `safetensors` crate.
///
/// This struct is kept for API compatibility. It records the checkpoint path
/// and loading strategy, but actual weight loading is deferred to the caller.
#[derive(Debug)]
pub struct LazyCheckpointLoader {
    /// Path to the checkpoint file.
    pub checkpoint_path: PathBuf,
    /// Loading strategy.
    pub strategy: LoadStrategy,
}

impl LazyCheckpointLoader {
    /// Create a new lazy checkpoint loader.
    pub fn new<P: AsRef<Path>>(
        checkpoint_path: P,
        strategy: LoadStrategy,
    ) -> Result<Self, MLError> {
        let path = checkpoint_path.as_ref().to_path_buf();
        if !path.exists() {
            return Err(MLError::CheckpointError(format!(
                "Checkpoint not found: {}",
                path.display()
            )));
        }
        Ok(Self {
            checkpoint_path: path,
            strategy,
        })
    }

    /// Get the checkpoint path.
    pub fn path(&self) -> &Path {
        &self.checkpoint_path
    }
}
