//! Directive CLI commands for autonomous goal-driven orchestration.
//!
//! Directives are top-level goals that the system works toward. Each directive
//! generates a chain of steps that are executed autonomously with configurable
//! guardrails.

use clap::Args;
use uuid::Uuid;

/// Common arguments for directive commands requiring API access.
#[derive(Args, Debug, Clone)]
pub struct DirectiveArgs {
    /// API URL
    #[arg(long, env = "MAKIMA_API_URL", default_value = "https://api.makima.jp", global = true)]
    pub api_url: String,

    /// API key for authentication
    #[arg(long, env = "MAKIMA_API_KEY", global = true)]
    pub api_key: String,
}

/// Arguments for the `create` command.
#[derive(Args, Debug)]
pub struct CreateArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// The goal for the directive
    #[arg(short, long)]
    pub goal: String,

    /// Repository URL (optional)
    #[arg(short, long)]
    pub repository: Option<String>,

    /// Autonomy level: full_auto, guardrails, or manual
    #[arg(short, long, default_value = "guardrails")]
    pub autonomy: String,
}

/// Arguments for the `status` command.
#[derive(Args, Debug)]
pub struct StatusArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `list` command.
#[derive(Args, Debug)]
pub struct ListArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Filter by status (draft, planning, active, paused, completed, archived, failed)
    #[arg(long)]
    pub status: Option<String>,

    /// Limit number of results
    #[arg(long, default_value = "50")]
    pub limit: i32,
}

/// Arguments for the `steps` command.
#[derive(Args, Debug)]
pub struct StepsArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `events` command.
#[derive(Args, Debug)]
pub struct EventsArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,

    /// Limit number of events
    #[arg(long, default_value = "50")]
    pub limit: i32,
}

/// Arguments for the `approve` command.
#[derive(Args, Debug)]
pub struct ApproveArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,

    /// Approval ID
    pub approval_id: Uuid,

    /// Response message (optional)
    #[arg(short, long)]
    pub response: Option<String>,
}

/// Arguments for the `deny` command.
#[derive(Args, Debug)]
pub struct DenyArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,

    /// Approval ID
    pub approval_id: Uuid,

    /// Reason for denial (optional)
    #[arg(short, long)]
    pub reason: Option<String>,
}

/// Arguments for the `start` command.
#[derive(Args, Debug)]
pub struct StartArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `pause` command.
#[derive(Args, Debug)]
pub struct PauseArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `resume` command.
#[derive(Args, Debug)]
pub struct ResumeArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `stop` command.
#[derive(Args, Debug)]
pub struct StopArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `archive` command.
#[derive(Args, Debug)]
pub struct ArchiveArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,
}

/// Arguments for the `graph` command (ASCII DAG visualization).
#[derive(Args, Debug)]
pub struct GraphArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Directive ID
    pub directive_id: Uuid,

    /// Show step status in nodes
    #[arg(long)]
    pub with_status: bool,
}
