index : license-api-rs.git

ascending towards madness

use std::fmt::Display;

#[derive(Debug)]
pub enum ErrorMsg {
    DatabaseError,
    NoLicensesAvailable,
    InvalidLicenseRequest,
    InvalidLicense,
    LicenseReadError,
}

impl Display for ErrorMsg {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let message = match self {
            ErrorMsg::LicenseReadError => "Unable to read license file:",
            ErrorMsg::DatabaseError => "Unable to load or parse license database.",
            ErrorMsg::NoLicensesAvailable => "No licenses found.",
            ErrorMsg::InvalidLicenseRequest => {
                //TODO: make this not hardcoded
                "Invalid license. use the 'list' or 'list/all' endpoints to see defined licenses."
            }
            ErrorMsg::InvalidLicense => "Invalid license requested:",
        };
        write!(f, "{}", message)
    }
}

#[derive(Debug)]
pub enum SuccessMsg {
    DatabaseLoaded,
}

impl Display for SuccessMsg {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let message = match self {
            SuccessMsg::DatabaseLoaded => "Database loaded successfully!",
        };
        write!(f, "{}", message)
    }
}