//! D-Bus error type. Maps `DbError` onto the `org.liberux.CallLog1.Error.*`
//! namespace.

use crate::db::DbError;

#[ derive( Debug, zbus::DBusError ) ]
#[ zbus( prefix = "org.liberux.CallLog1.Error" ) ]
pub enum Error
{
	#[ zbus( error ) ]
	ZBus( zbus::Error ),

	NotFound( String ),
	InvalidArgument( String ),
	Internal( String ),
}

impl From<DbError> for Error
{
	fn from( e: DbError ) -> Self
	{
		match e
		{
			DbError::NotFound        => Error::NotFound( "no such call".into() ),
			DbError::Sqlite( inner ) => Error::Internal( format!( "sqlite: {inner}" ) ),
		}
	}
}
