use thiserror::Error;
use wasm_bindgen::JsValue;

#[derive(Debug, Error)]
pub enum BrowserCoreError {
    #[error("invalid hex value: {0}")]
    InvalidHex(String),
    #[error("invalid FN-DSA private key")]
    InvalidPrivateKey,
    #[error("invalid FN-DSA public key")]
    InvalidPublicKey,
    #[error("invalid FN-DSA signature")]
    InvalidSignature,
    #[error("invalid Contractless address: {0}")]
    InvalidAddress(String),
    #[error("invalid transfer transaction: {0}")]
    InvalidTransfer(String),
    #[error("JSON serialization failed: {0}")]
    Json(String),
    #[error("unsupported transaction type: {0}")]
    UnsupportedTransaction(u8),
    #[error("invalid transaction request: {0}")]
    InvalidRequest(String),
}

impl From<BrowserCoreError> for JsValue {
    fn from(error: BrowserCoreError) -> Self {
        JsValue::from_str(&error.to_string())
    }
}
