use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid magic bytes: file is not a valid TapirusDB database")]
InvalidMagic,
#[error("Invalid page size {0}: must be power of 2 between 512 and 65536")]
InvalidPageSize(u16),
#[error("Page {0} corrupted: checksum mismatch (expected {1:#x}, found {2:#x})")]
PageCorrupted(u32, u32, u32),
#[error("Page {0} not found in database file")]
PageNotFound(u32),
#[error("SQL syntax error: {0}")]
SqlSyntax(String),
#[error("Table '{0}' already exists")]
TableExists(String),
#[error("Table '{0}' does not exist")]
TableNotFound(String),
#[error("Vector dimension mismatch: expected {0} dimensions, got {1}")]
DimensionMismatch(usize, usize),
#[error("Decryption failed for page {0}: invalid encryption key or corrupted ciphertext")]
DecryptionFailed(u32),
#[error("Database is encrypted: encryption key required to open")]
EncryptedDatabase,
#[error("Transaction error: {0}")]
TransactionError(String),
#[error("Database corrupted: {0}")]
Corrupted(String),
#[error("Constraint violation: {0}")]
ConstraintViolation(String),
#[error("Database busy: {0}")]
Busy(String),
#[error("Serialization error: {0}")]
Serialization(String),
}