use std::io;
use std::time::Duration;
use thiserror::Error;
use super::dns::DnsProviderError;
#[derive(Debug, Error)]
pub enum AcmeError {
#[error("ACME account not initialized - call init_account() first")]
NoAccount,
#[error("Failed to create ACME account: {0}")]
AccountCreation(String),
#[error("Failed to create certificate order: {0}")]
OrderCreation(String),
#[error("Challenge validation failed for domain '{domain}': {message}")]
ChallengeValidation { domain: String, message: String },
#[error("Failed to finalize certificate: {0}")]
Finalization(String),
#[error("Storage error: {0}")]
Storage(#[from] StorageError),
#[error("ACME protocol error: {0}")]
Protocol(String),
#[error("Operation timed out: {0}")]
Timeout(String),
#[error("No HTTP-01 challenge available for domain '{0}'")]
NoHttp01Challenge(String),
#[error("No DNS-01 challenge available for domain '{0}'")]
NoDns01Challenge(String),
#[error("DNS-01 challenge requires a DNS provider configuration")]
NoDnsProvider,
#[error("DNS provider error: {0}")]
DnsProvider(#[from] DnsProviderError),
#[error("DNS propagation timeout for record '{record}' after {elapsed:?}")]
PropagationTimeout { record: String, elapsed: Duration },
#[error("Wildcard domain '{domain}' requires DNS-01 challenge type")]
WildcardRequiresDns01 { domain: String },
#[error("Failed to parse certificate: {0}")]
CertificateParse(String),
}
#[derive(Debug, Error)]
pub enum StorageError {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Storage directory not writable: {path}")]
NotWritable { path: String },
#[error("Certificate not found for domain: {domain}")]
CertificateNotFound { domain: String },
#[error("Invalid storage structure: {0}")]
InvalidStructure(String),
}
impl From<serde_json::Error> for StorageError {
fn from(e: serde_json::Error) -> Self {
StorageError::Serialization(e.to_string())
}
}
impl From<instant_acme::Error> for AcmeError {
fn from(e: instant_acme::Error) -> Self {
AcmeError::Protocol(e.to_string())
}
}