// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright © 2024 Mike Robeson [dijksterhuis]

// use std::path::Path;
// use std::path::PathBuf;
//
// use ot_tools_io::OctatrackFileIO;
// use ot_tools_io::SampleSettingsFile;
// use crate::projects::DataItem;
// use crate::projects::DataSource;
// use crate::projects::R;
// use crate::OtToolsInterfacesError;

// /// Alias of a [`DataItem`] container for the [`SampleSettingsFile`] type
// pub type SampleSettingDataFile = DataItem<SampleSettingsFile>;
//
// // WARN: cannot use associated methods like `Self::new()` here as
// // SampleSettingsFile does not implement the `Default` trait
// impl SampleSettingDataFile {
//     fn get_path(
//         dirpath: &Path,
//         file_name: &str,
//     ) -> PathBuf {
//         dirpath.join(format!["{file_name}.ot"])
//     }
//
//     pub fn create(
//         dirpath: &Path,
//         file_name: &str,
//     ) -> R<Self> {
//         let path = Self::get_path(dirpath, file_name);
//         let data = SampleSettingsFile::from_data_file(&path)?;
//         Self::new(DataSource(path), data)
//     }
//
//     pub fn load(
//         dirpath: &Path,
//         file_name: &str,
//     ) -> R<Self> {
//         let path = Self::get_path(dirpath, file_name);
//         Self::from(DataSource(path))
//     }
//
//     pub fn to_new(
//         &self,
//         new_dirpath: &Path,
//         file_name: &str,
//     ) -> R<Self> {
//         let path = Self::get_path(new_dirpath, file_name);
//         let mut new = self.clone();
//         new.source = DataSource(path);
//
//         Ok(new)
//     }
//
//     pub fn is_default(&self) -> R<bool> {
//         Err(OtToolsInterfacesError::NoDataSource)
//     }
// }

// /// Helper type -- data for some type which will be written to some file at
// /// `file_path`.
// #[derive(Clone, PartialEq, Debug)]
// pub struct FileWithPath<T> {
//     pub data: Option<T>,
//     pub file_path: PathBuf,
// }
//
// /// A pair of audio and sample settings files (data and paths to the files).
// #[derive(Clone, PartialEq, Debug)]
// pub struct SampleFilePair {
//     pub audio_file: FileWithPath<AudioFile>,
//     pub settings_file: Option<FileWithPath<SampleSettingsFile>>,
// }
//
// impl SampleFilePair {
//     /// Writes both files to the previously configured path for a single sample
//     /// chain
//     pub fn write(self) -> R<()> {
//         if let Some(x) = self.audio_file.data {
//             x.write_by_ext(&self.audio_file.file_path)?;
//         }
//         // audio file has a settings file
//         if let Some(settings) = self.settings_file {
//             // we have loaded the data for file
//             if let Some(x) = settings.data {
//                 x.to_data_file(&settings.file_path)?;
//             }
//
//         }
//
//         Ok(())
//     }
// }
//
// /// Helper struct to track where to write an [`AudioFile`] after processing.
// pub type AudioFileWithPath = FileWithPath<AudioFile>;
//
// impl AudioFileWithPath {
//     /// Write audio file to the previously configured path *and* create a new
//     /// sample settings file for the audio file
//     pub fn write(self) -> R<()> {
//         if let Some(x) = self.data {
//             x.write_by_ext(&self.file_path)?;
//         }
//         new_settings_file(&self.file_path, None)?;
//         Ok(())
//     }
// }
//
// /// Collection of [`AudioFileWithPath`] instances
// #[derive(Clone, Debug)]
// pub struct AudioFilesWithPath(Vec<AudioFileWithPath>);
//
// impl AudioFilesWithPath {
//     fn new() -> Self {
//         Self(Vec::new())
//     }
//
//     pub fn is_empty(&self) -> bool {
//         self.0.is_empty()
//     }
//
//     /// Number of [`AudioFileWithPath`] instances in the collection
//     pub fn len(&self) -> usize {
//         self.0.len()
//     }
//
//     pub fn push(&mut self, value: AudioFileWithPath) {
//         self.0.push(value);
//     }
//
//     /// Writes all individual chains to their configured location
//     pub fn write(self) -> R<()> {
//         for f in self.0 {
//             f.write()?;
//         }
//         Ok(())
//     }
// }
//
// impl Index<usize> for AudioFilesWithPath {
//     type Output = AudioFileWithPath;
//
//     fn index(&self, index: usize) -> &Self::Output {
//         self.0.index(index)
//     }
// }
