use std::path::{Path, PathBuf};

use crate::{
    error::MtagResult,
    executor::{execute_plan, ExecutionOptions, ExecutionSummary},
    metadata::read_track_metadata,
    planner::{build_copy_plan, OrganizationOptions},
};

/// Organizes a list of audio files into the target folder using default options.
///
/// This function is kept for callers that used the original crate API. New code can use
/// [`crate::metadata::read_track_metadata`], [`crate::planner::build_copy_plan`], and
/// [`crate::executor::execute_plan`] directly for finer control.
///
/// # Errors
///
/// Returns metadata, planning, or execution errors from the underlying modules.
pub fn organizer_start(
    files_list: Vec<PathBuf>,
    target_folder_path: &Path,
) -> MtagResult<ExecutionSummary> {
    let tracks = files_list
        .iter()
        .map(|path| read_track_metadata(path))
        .collect::<MtagResult<Vec<_>>>()?;
    let plan = build_copy_plan(&tracks, target_folder_path, &OrganizationOptions::default())?;

    execute_plan(&plan, &ExecutionOptions::default())
}
