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

mod helpers;
use helpers::*;
use ot_tools_io::{ArrangementFile, BankFile, MarkersFile, OctatrackFileIO, ProjectFile};
use std::path::PathBuf;

#[derive(Debug)]
#[allow(dead_code)]
struct Metadata {
    header: String,
    datatype_version: u8,
}

// read different data files and print some metadata
fn main() -> RBoxErr<()> {
    let blank_project_dirpath = PathBuf::from("test-data").join("blank-project");

    let arr_fpath = blank_project_dirpath.join("arr01.work");
    let bank_fpath = blank_project_dirpath.join("bank01.work");
    let markers_fpath = blank_project_dirpath.join("markers.work");
    let project_fpath = blank_project_dirpath.join("project.work");

    let arr = ArrangementFile::from_data_file(&arr_fpath)?;
    let bank = BankFile::from_data_file(&bank_fpath)?;
    let markers = MarkersFile::from_data_file(&markers_fpath)?;
    let project = ProjectFile::from_data_file(&project_fpath)?;

    let arr_meta = Metadata {
        header: String::from_utf8_lossy(&arr.header)
            .to_string()
            .replace("\0", "."),
        datatype_version: arr.datatype_version,
    };

    let bank_meta = Metadata {
        header: String::from_utf8_lossy(&bank.header)
            .to_string()
            .replace("\0", "."),
        datatype_version: bank.datatype_version,
    };

    let markers_meta = Metadata {
        header: String::from_utf8_lossy(&markers.header)
            .to_string()
            .replace("\0", "."),
        datatype_version: markers.datatype_version,
    };

    println!("===================================");
    println!("| Printing example files metadata |");
    println!("===================================");
    println!();
    println!("project: {:#?}", project.metadata);
    println!();
    println!("arrangement: {arr_meta:#?}");
    println!();
    println!("bank: {bank_meta:#?}");
    println!();
    println!("markers: {markers_meta:#?}");
    Ok(())
}
