use thiserror::Error;
use toml;
// Kam的错误类型，避免在公共API里用Box<dyn Error>
// 用thiserror自动生成Error trait实现
/// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
#[derive(Error, Debug)]
pub enum KamError {
    #[error("IO error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'Io' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    Io(#[from] std::io::Error),

    #[error("Zip error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'Zip' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    Zip(#[from] zip::result::ZipError),

    #[error("TOML error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'Toml' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    Toml(String),

    #[error("JSON error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'Json' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    Json(String),

    #[error("Walkdir error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'Walkdir' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    Walkdir(#[from] walkdir::Error),

    #[error("KamToml error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'KamToml' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    KamToml(#[from] crate::errors::KamTomlError),

    #[error("Command failed: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'CommandFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    CommandFailed(String),

    #[error("请安装shellcheck")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'ShellcheckMissing' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    ShellcheckMissing,

    #[error("Invalid directory: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidDirectory' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidDirectory(String),

    #[error("Package not found: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'PackageNotFound' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    PackageNotFound(String),

    #[error("Invalid filename: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidFilename' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidFilename(String),

    #[error("Upload failed: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'UploadFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    UploadFailed(String),

    #[error("Fetch failed: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'FetchFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    FetchFailed(String),

    #[error("Virtual environment already exists: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'VenvExists' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    VenvExists(String),

    #[error("Virtual environment not found: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'VenvNotFound' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    VenvNotFound(String),

    #[error("Required template variable not provided: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'TemplateVarRequired' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    TemplateVarRequired(String),

    #[error("Invalid config: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidConfig' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidConfig(String),

    #[error("Unsupported archive format: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'UnsupportedArchive' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    UnsupportedArchive(String),

    #[error("Template not found: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'TemplateNotFound' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    TemplateNotFound(String),

    #[error("Library not found: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'LibraryNotFound' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    LibraryNotFound(String),

    #[error("Extract failed: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'ExtractFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    ExtractFailed(String),

    #[error("Unsupported format: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'UnsupportedFormat' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    UnsupportedFormat(String),

    #[error("Invalid URL: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidUrl' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidUrl(String),

    #[error("Implementation requires template variables: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'ImplRequiresVars' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    ImplRequiresVars(String),

    #[error("Invalid template variable format: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidVarFormat' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidVarFormat(String),

    #[error("Repo template not found: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'RepoTemplateNotFound' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    RepoTemplateNotFound(String),

    #[error("Unknown template type: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'UnknownTemplateType' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    UnknownTemplateType(String),

    #[error("Failed to create table: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'TableCreationFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    TableCreationFailed(String),

    #[error("Invalid module type: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidModuleType' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidModuleType(String),

    #[error("Parse source spec failed: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'ParseSourceFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    ParseSourceFailed(String),

    #[error("Venv create failed: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'VenvCreateFailed' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    VenvCreateFailed(String),

    #[error("Invalid module structure: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'InvalidModuleStructure' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    InvalidModuleStructure(String),

    #[error("Template render error: {0}")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public enum variant 'TemplateRenderError' in 'KamError'. Replace with real documentation. (2025-12-30T22:23:21Z)
    TemplateRenderError(String),
}

impl From<toml_edit::TomlError> for KamError {
    fn from(e: toml_edit::TomlError) -> Self {
        Self::Toml(format!("TOML edit error: {e}"))
    }
}

impl From<toml_edit::de::Error> for KamError {
    fn from(e: toml_edit::de::Error) -> Self {
        Self::Toml(format!("TOML schema error: {e}"))
    }
}

impl From<toml::de::Error> for KamError {
    fn from(e: toml::de::Error) -> Self {
        Self::Toml(format!("TOML deserialization error: {e}"))
    }
}

impl From<toml::ser::Error> for KamError {
    fn from(e: toml::ser::Error) -> Self {
        Self::Toml(format!("TOML serialization error: {e}"))
    }
}

impl From<serde_json::Error> for KamError {
    fn from(e: serde_json::Error) -> Self {
        Self::Json(format!("JSON error: {e}"))
    }
}

impl From<std::path::StripPrefixError> for KamError {
    fn from(e: std::path::StripPrefixError) -> Self {
        Self::InvalidDirectory(format!("strip_prefix failed: {e}"))
    }
}
