use std::time::Duration;

use crate::vms::VmId;

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    /// A required external tool couldn't be found.
    #[error("Couldn't find {tool} in {searched}")]
    MissingTool {
        tool: &'static str,
        searched: &'static str,
    },

    /// The host doesn't support vsock (which is how vmexec talks to the guest).
    #[error(
        "vsock is not supported on this system. \
         This usually means the vhost_vsock kernel module is not loaded. \
         Try running: sudo modprobe vhost_vsock"
    )]
    VsockUnavailable,

    /// A VM with the requested id already exists.
    #[error("vmid '{0}' already exists")]
    VmIdExists(VmId),

    /// No VM with the requested id exists.
    #[error("no virtual machine with vmid '{0}'")]
    VmNotFound(VmId),

    /// The VM didn't become reachable over SSH before the timeout elapsed.
    #[error("Reached timeout trying to connect to virtual machine via SSH, aborting")]
    SshTimeout(Duration),

    #[error(transparent)]
    Other(#[from] eyre::Report),
}
