//! Command trait for uniform execution

use super::context::CommandContext;
use super::error::CommandResult;
use async_trait::async_trait;

/// Trait for CLI commands
///
/// All commands implement this trait to provide a uniform execution interface.
/// This makes commands easier to test, compose, and maintain.
///
/// # Example
///
/// ```rust,ignore
/// pub struct BuildCommand {
///     release: bool,
///     target: Option<String>,
/// }
///
/// #[async_trait]
/// impl Command for BuildCommand {
///     async fn execute(&self, ctx: &mut CommandContext) -> CommandResult<()> {
///         // Implementation here
///         Ok(())
///     }
/// }
/// ```
#[async_trait]
pub trait Command: Send + Sync {
    /// Execute the command
    ///
    /// # Arguments
    /// * `ctx` - Command context with shared state and configuration
    ///
    /// # Returns
    /// * `Ok(())` on success
    /// * `Err(CommandError)` on failure
    async fn execute(&self, ctx: &mut CommandContext) -> CommandResult<()>;

    /// Get the command name (for logging and error messages)
    fn name(&self) -> &'static str {
        "command"
    }

    /// Validate command arguments before execution
    ///
    /// Override this to perform pre-execution validation.
    /// Default implementation returns Ok.
    fn validate(&self) -> CommandResult<()> {
        Ok(())
    }
}
