//! Pull Request (PR) command definitions.
//!
//! Commands for managing GitHub-style pull requests.

use super::super::command::{CommandCategory, CommandDef, CommandId};
use crate::app::Action;

pub fn pr_commands() -> Vec<CommandDef> {
    vec![
        CommandDef {
            id: CommandId::PrHelper,
            name: "PR helper",
            key: "prh",
            category: CommandCategory::Pr,
            description: "Show PR helper",
            action_factory: |_| Some(Action::ShowPrHelper),
            is_enabled: |_| true,
            keywords: &["pr", "helper", "pull", "request"],
        },
        CommandDef {
            id: CommandId::PrOpen,
            name: "Open PR",
            key: "pro",
            category: CommandCategory::Pr,
            description: "Open PR in browser",
            action_factory: |state| {
                if !state.pr_list.is_empty() && state.pr_selected < state.pr_list.len() {
                    Some(Action::OpenPrInBrowser(state.pr_list[state.pr_selected].number.clone()))
                } else {
                    None
                }
            },
            is_enabled: |state| !state.pr_list.is_empty() && state.pr_selected < state.pr_list.len(),
            keywords: &["pr", "open", "browser"],
        },
        CommandDef {
            id: CommandId::PrCheckout,
            name: "Checkout PR",
            key: "prc",
            category: CommandCategory::Pr,
            description: "Checkout PR branch",
            action_factory: |state| {
                if !state.pr_list.is_empty() && state.pr_selected < state.pr_list.len() {
                    Some(Action::CheckoutPr(state.pr_list[state.pr_selected].number.clone()))
                } else {
                    None
                }
            },
            is_enabled: |state| !state.pr_list.is_empty() && state.pr_selected < state.pr_list.len(),
            keywords: &["pr", "checkout", "branch"],
        },
    ]
}

