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

mod helpers;

use helpers::*;
use ot_tools_io::OctatrackFileIO;
#[allow(unused_imports)]
use ot_tools_io::{ArrangementFile, BankFile, MarkersFile, ProjectFile, SampleSettingsFile};

#[test]
fn arrangement_blank() -> RBoxErr<()> {
    // let valid_json_path = std::path::Path::new("TODO");

    let binpath = get_arrange_dirpath().join("blank.work");
    let outjson = std::env::temp_dir().join("serde-ot-bin2yaml-arrange-blank.json");

    let r = ArrangementFile::from_data_file(&binpath)?.to_json_file(&outjson);
    print_and_assert_ok_result(r);
    Ok(())
}

#[test]
fn arrangement_full_options() -> RBoxErr<()> {
    // let valid_json_path = std::path::Path::new("TODO");
    let binpath = get_arrange_dirpath().join("full-options.work");
    let outjson = std::env::temp_dir().join("serde-ot-bin2yaml-arrange-full.json");

    let r = ArrangementFile::from_data_file(&binpath)?.to_json_file(&outjson);
    print_and_assert_ok_result(r);
    Ok(())
}

#[test]
fn arrangement_one_reminder_row() -> RBoxErr<()> {
    // let valid_json_path = std::path::Path::new("TODO");
    let binpath = get_arrange_dirpath().join("1-rem-blank-txt.work");
    let outjson = std::env::temp_dir().join("serde-ot-bin2yaml-arrange-one_rem_row_blank.json");

    let r = ArrangementFile::from_data_file(&binpath)?.to_json_file(&outjson);
    print_and_assert_ok_result(r);
    Ok(())
}

#[test]
fn test_bank() -> RBoxErr<()> {
    let outfile = std::env::temp_dir().join("ot-tools-actions-bin2yaml-bank-ok.json");
    let binfile = get_blank_proj_dirpath().join("bank01.work");
    let r = BankFile::from_data_file(&binfile)?.to_json_file(&outfile);
    let _ = std::fs::remove_file(&outfile);
    assert!(r.is_ok());
    Ok(())
}

#[test]
fn test_project() -> RBoxErr<()> {
    let outfile = std::env::temp_dir().join("ot-tools-actions-bin2yaml-project-ok.json");
    let binfile = get_blank_proj_dirpath().join("project.work");
    let r = ProjectFile::from_data_file(&binfile)?.to_json_file(&outfile);
    let _ = std::fs::remove_file(&outfile);
    assert!(r.is_ok());
    Ok(())
}

#[test]
fn test_sample() -> RBoxErr<()> {
    let outfile = std::env::temp_dir().join("ot-tools-actions-bin2yaml-sample-ok.json");
    let binfile = get_samples_dirpath().join("sample.ot");
    let r = SampleSettingsFile::from_data_file(&binfile)?.to_json_file(&outfile);
    let _ = std::fs::remove_file(&outfile);
    assert!(r.is_ok());
    Ok(())
}
