use std::error::Error;
use std::fmt::{Display, Formatter};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrmError {
    pub message: String
}

impl From<sqlx::Error> for OrmError {
    fn from(value: sqlx::Error) -> Self {
        OrmError {
            message: value.to_string()
        }
    }
}

impl From<std::io::Error> for OrmError {
    fn from(value: std::io::Error) -> Self {
        OrmError {
            message: value.to_string()
        }
    }
}

impl Display for OrmError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.message.as_str())
    }
}

impl Error for OrmError {}