use libk_mm::address::PhysicalAddress;
use yggdrasil_abi::error::Error;

use super::queue::CommandError;

#[derive(Debug)]
pub enum NvmeError {
    InitError(Error),
    InvalidBuffer(PhysicalAddress, usize),
    RequestTooLarge(usize),
    MemoryError(Error),
    CommandError(CommandError),
}

impl From<CommandError> for NvmeError {
    fn from(value: CommandError) -> Self {
        Self::CommandError(value)
    }
}

impl From<NvmeError> for Error {
    fn from(value: NvmeError) -> Self {
        match value {
            NvmeError::InitError(error) => error,
            NvmeError::RequestTooLarge(_) => Error::InvalidArgument,
            NvmeError::InvalidBuffer(_, _) => Error::InvalidArgument,
            NvmeError::MemoryError(err) => err,
            // TODO Error::DeviceError
            NvmeError::CommandError(_err) => Error::InvalidArgument,
        }
    }
}
