//! Directive subcommand - directive management commands for orchestrator tasks.

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

/// Common arguments for directive commands.
#[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,

    /// Directive ID
    #[arg(long, env = "MAKIMA_DIRECTIVE_ID", global = true)]
    pub directive_id: Uuid,
}

/// Arguments for listing directives (no directive_id required).
#[derive(Args, Debug, Clone)]
pub struct DirectiveListArgs {
    /// 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 add-step command.
#[derive(Args, Debug)]
pub struct AddStepArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Step name
    pub name: String,

    /// Step description
    #[arg(long)]
    pub description: Option<String>,

    /// Task plan for the step
    #[arg(long)]
    pub task_plan: Option<String>,

    /// Comma-separated UUIDs of dependency steps
    #[arg(long)]
    pub depends_on: Option<String>,

    /// Order index
    #[arg(long, default_value = "0")]
    pub order_index: i32,
}

/// Arguments for remove-step command.
#[derive(Args, Debug)]
pub struct RemoveStepArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Step ID to remove
    pub step_id: Uuid,
}

/// Arguments for set-deps command.
#[derive(Args, Debug)]
pub struct SetDepsArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Step ID to update
    pub step_id: Uuid,

    /// Comma-separated UUIDs of dependency steps
    pub depends_on: String,
}

/// Arguments for complete-step/fail-step/skip-step commands.
#[derive(Args, Debug)]
pub struct StepActionArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// Step ID
    pub step_id: Uuid,
}

/// Arguments for update-goal command.
#[derive(Args, Debug)]
pub struct UpdateGoalArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// New goal text
    pub goal: String,
}

/// Arguments for batch-add-steps command.
#[derive(Args, Debug)]
pub struct BatchAddStepsArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// JSON array of steps: [{"name":"...","description":"...","taskPlan":"...","dependsOn":[],"orderIndex":0}]
    #[arg(long)]
    pub json: String,
}

/// Arguments for update command.
#[derive(Args, Debug)]
pub struct UpdateArgs {
    #[command(flatten)]
    pub common: DirectiveArgs,

    /// PR URL to store on the directive
    #[arg(long)]
    pub pr_url: Option<String>,

    /// PR branch name to store on the directive
    #[arg(long)]
    pub pr_branch: Option<String>,
}

