use std::io;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum NoxuLogError {
#[error("Log I/O error: {0}")]
Io(#[from] io::Error),
#[error("Log file not found: {0}")]
FileNotFound(String),
#[error("Checksum validation failed at LSN {lsn}: {message}")]
Checksum { lsn: noxu_util::lsn::Lsn, message: String },
#[error("Invalid file header in file {file_num:08x}: {message}")]
InvalidHeader { file_num: u32, message: String },
#[error(
"Version mismatch: expected {expected}, found {found} in file {file_num:08x}"
)]
VersionMismatch { expected: u32, found: u32, file_num: u32 },
#[error("Environment locked: {0}")]
EnvironmentLocked(String),
#[error("Invalid environment directory: {0}")]
InvalidDirectory(String),
#[error("Log write failed: {0}")]
WriteFailed(String),
#[error("Invalid entry type {type_num} at LSN {lsn}")]
InvalidEntryType { type_num: u8, lsn: noxu_util::lsn::Lsn },
#[error("Invalid entry size {size} at LSN {lsn}")]
InvalidEntrySize { size: i32, lsn: noxu_util::lsn::Lsn },
#[error("Unexpected EOF at LSN {lsn}: {message}")]
UnexpectedEof { lsn: noxu_util::lsn::Lsn, message: String },
#[error("Buffer overflow: {0}")]
BufferOverflow(String),
#[error("Log corrupt: {0}")]
LogCorrupt(String),
#[error("Latch acquisition timed out: {0}")]
LatchTimeout(String),
#[error("Internal error: {0}")]
Internal(String),
}
pub type LogError = NoxuLogError;
pub type Result<T> = std::result::Result<T, NoxuLogError>;