from __future__ import annotations

import pandas as pd


def df_for_export(df: pd.DataFrame) -> pd.DataFrame:
    export = df.copy()
    index_name = export.index.name if export.index.name else "index"
    export = export.reset_index()
    if index_name in export.columns:
        export = export.rename(columns={index_name: "timestamp"})
    else:
        # Fallback for uncommon index/column collisions.
        export = export.rename(columns={export.columns[0]: "timestamp"})

    if pd.api.types.is_datetime64_any_dtype(export["timestamp"]):
        export["timestamp"] = export["timestamp"].astype(str)
    return export
