#[cfg(feature = "write_minidump")]
use minidump_writer::MinidumpType;
#[cfg(feature = "write_minidump")]
use std::fs::File;

#[cfg(feature = "write_minidump")]
pub fn write_minidump(
    minidump_file_destination: String,
    exception_code: Option<i32>,
) -> Result<(), minidump_writer::errors::Error> {
    let minidump_destination_file: Result<File, std::io::Error> =
        File::create(minidump_file_destination);

    match minidump_destination_file {
        Ok(_) => (),
        Err(err) => return Err(minidump_writer::errors::Error::Io(err)),
    }

    // The arguments for the minidump writer function.
    let mdarg_exception_code: Option<i32> = exception_code; // The exception code as an i32.
    let mdarg_thread_id: Option<u32> = Some(thread_id::get() as u32); // The thread id which will be minidumped.
    let mdarg_minidump_type: Option<MinidumpType> = Some(MinidumpType::empty()); // The minidump type (Look at the implementation for all the valid values).
    let mdarg_destination_file: &mut File = &mut minidump_destination_file.unwrap(); // The destination file where the minidump will be written to.

    // Writes the minidump.
    minidump_writer::minidump_writer::MinidumpWriter::dump_local_context(
        mdarg_exception_code,
        mdarg_thread_id,
        mdarg_minidump_type,
        mdarg_destination_file,
    )
}
