//! Typed error types for [`WalletManager`](crate::WalletManager) operations.
//!
//! # Key material
//! No variant carries key material (mnemonics, private keys, scalars).
//! String payloads contain only OS/library error descriptions.

/// Errors returned by [`WalletManager`](crate::WalletManager) public methods.
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum WalletError {
    /// The wallet is locked — no key material is in memory.
    ///
    /// Unlock the wallet before calling signing or key-derivation methods.
    #[error("wallet is locked")]
    Locked,

    /// A signing payload exceeds the maximum allowed size.
    #[error("payload too large: {size} bytes (max {max})")]
    PayloadTooLarge {
        /// The size of the rejected payload in bytes.
        size: usize,
        /// The maximum allowed payload size in bytes.
        max: usize,
    },

    /// The `app_id` string exceeds the maximum allowed length.
    #[error("app_id too long: {len} bytes (max {max})")]
    AppIdTooLong {
        /// The byte length of the rejected app_id.
        len: usize,
        /// The maximum allowed byte length.
        max: usize,
    },

    /// A BIP-39 mnemonic phrase could not be parsed.
    ///
    /// Returned by `import`, `load_from_mnemonic`, and `unlock` (if the
    /// keystore-stored phrase is corrupted). The inner string is the parse
    /// error — it does not contain the mnemonic itself.
    #[error("invalid mnemonic: {0}")]
    InvalidMnemonic(String),

    /// BIP-39 entropy generation failed (CSPRNG failure).
    ///
    /// Returned only by `create`. Indicates a catastrophic OS failure.
    #[error("mnemonic generation failed: {0}")]
    MnemonicGenerationFailed(String),

    /// The platform keystore (macOS Keychain, keyring crate) returned an error.
    ///
    /// The inner string is the OS/library error, suitable for logging.
    #[error("keystore error: {0}")]
    Keystore(String),

    /// An ETH secp256k1 signing operation failed.
    #[error("ETH signing failed: {0}")]
    EthSigningFailed(String),

    /// A BTC secp256k1 signing operation failed.
    #[error("BTC signing failed: {0}")]
    BtcSigningFailed(String),

    /// A Substrate ECDSA signing operation failed.
    #[error("Substrate ECDSA signing failed: {0}")]
    SubstrateEcdsaFailed(String),

    /// P-256 key derivation from an sr25519 scalar failed.
    #[error("P-256 derivation failed: {0}")]
    P256DerivationFailed(String),
}

/// Convenience alias — `WalletResult<T>` is `Result<T, WalletError>`.
pub type WalletResult<T> = Result<T, WalletError>;
