"""Save and load emzed tables in a temporary folder."""

from pathlib import Path
from tempfile import TemporaryDirectory

import emzed

peaks = emzed.Table.create_table(
    ["compound", "mz", "rt"],
    [str, emzed.MzType, emzed.RtType],
    rows=[
        ["caffeine", 195.08765, 42.0],
        ["glucose", 181.07066, 60.0],
    ],
)

with TemporaryDirectory() as tmp:
    folder = Path(tmp)
    table_path = folder / "peaks.table"
    csv_path = folder / "peaks.csv"
    xlsx_path = folder / "peaks.xlsx"

    emzed.io.save_table(peaks, table_path)
    emzed.io.save_csv(peaks, csv_path)
    emzed.io.save_excel(peaks, xlsx_path)

    loaded = emzed.io.load_table(table_path)

    print(f"saved files in {folder}")
    print(f"loaded {len(loaded)} rows from {table_path.name}")
    print(loaded)
