//! Contract trait for command enums generated by `#[derive(CommandEnum)]`.

use clap::ArgMatches;

/// Shared interface for command enums generated by the `CommandEnum` derive macro.
///
/// Both primary enums (e.g., `Command`) and sub-command enums (e.g., `QueueCommand`)
/// implement this trait.
pub trait CommandEnumContract: Copy + Sized + 'static {
    /// All variants of this command enum.
    fn all() -> &'static [Self];
    /// Display name for documentation.
    fn doc_name(&self) -> &'static str;
    /// Option type names used by this command.
    fn options_names(&self) -> &'static [&'static str];
    /// Check if this command uses the given options type.
    fn uses_options(&self, name: &str) -> bool {
        self.options_names().contains(&name)
    }
    /// Resolve a command variant and its [`ArgMatches`] from the given matches.
    fn resolve(matches: &ArgMatches) -> Option<(Self, ArgMatches)>;
}
