use console::style;

pub fn run() {
    let groups = [
        (
            "Project Generation",
            vec![
                (
                    "rok new <name>",
                    "Scaffold a new rok/Axum project from a template",
                ),
                (
                    "rok new <name> -t <template>",
                    "Scaffold with specific template (api|saas|htmx|microservice|minimal)",
                ),
            ],
        ),
        (
            "make:* — Code Generators",
            vec![
                (
                    "rok make:controller <name>",
                    "Generate a controller (--resource for full CRUD)",
                ),
                (
                    "rok make:model <name>",
                    "Generate a model (--migration, --controller, --resource, --factory)",
                ),
                ("rok make:migration <name>", "Generate a SQL migration file"),
                ("rok make:seeder <name>", "Generate a database seeder"),
                ("rok make:validator <name>", "Generate a request validator"),
                ("rok make:observer <name>", "Generate a model observer"),
                (
                    "rok make:resource <name>",
                    "Generate an API resource transformer",
                ),
                ("rok make:scope <name>", "Generate a query scope"),
                ("rok make:policy <name>", "Generate an authorization policy"),
                ("rok make:job <name>", "Generate a background job"),
                ("rok make:event <name>", "Generate an event class"),
                ("rok make:listener <name>", "Generate an event listener"),
                ("rok make:notification <name>", "Generate a notification"),
                ("rok make:test <name>", "Generate a test file"),
                (
                    "rok make:locale <lang>",
                    "Generate a locale translation file",
                ),
                (
                    "rok make:crud <name>",
                    "Full CRUD scaffold (model, migration, controller, etc.)",
                ),
                (
                    "rok make:from-json <name> <json>",
                    "Generate model + migration from JSON",
                ),
                (
                    "rok make:from-schema <name>",
                    "Generate model + migration from JSON Schema",
                ),
                (
                    "rok make:ts-client",
                    "Generate TypeScript API client from resources",
                ),
                (
                    "rok make:scaffold [template]",
                    "Run a domain scaffold template (20 available)",
                ),
                (
                    "rok make:feature",
                    "Generate a complete feature from JSON spec",
                ),
            ],
        ),
        (
            "db:* — Database",
            vec![
                ("rok db:migrate", "Apply all pending migrations"),
                (
                    "rok db:update",
                    "Apply pending migrations with progress output",
                ),
                ("rok db:rollback", "Rollback the last migration batch"),
                ("rok db:status", "Show migration status"),
                ("rok db:seed", "Run database seeders"),
                ("rok db:fresh", "Drop all tables and re-run all migrations"),
                (
                    "rok db:pull <table>",
                    "Introspect a table and generate a model",
                ),
                ("rok db:diff <model>", "Compare model against live schema"),
            ],
        ),
        (
            "queue:* — Background Jobs",
            vec![
                ("rok queue:work", "Start the queue worker"),
                ("rok queue:status", "Show pending/running/failed job counts"),
                ("rok queue:retry --job-id <id>", "Retry a failed job"),
                ("rok queue:flush", "Delete failed jobs"),
            ],
        ),
        (
            "plan:* — Roadmap",
            vec![
                ("rok plan:next", "Show the next incomplete phase"),
                ("rok plan:list", "List all phases with status"),
                ("rok plan:graph", "Output dependency graph in DOT format"),
                ("rok plan:status --phase <N>", "Show phase status"),
            ],
        ),
        (
            "agent:* — AI Agent Integration",
            vec![
                ("rok agent:rules", "Print AI agent coding rules"),
                (
                    "rok agent:context --phase <N>",
                    "Show full context for a phase",
                ),
                (
                    "rok agent:feedback --progress <text>",
                    "Append progress feedback",
                ),
                (
                    "rok agent:claude --phase <N>",
                    "Launch Claude Code with rok context",
                ),
                (
                    "rok agent:opencode --phase <N>",
                    "Launch OpenCode with rok context",
                ),
            ],
        ),
        (
            "Utilities",
            vec![
                (
                    "rok publish",
                    "Publish all crates to crates.io (runs gates, creates tags)",
                ),
                (
                    "rok publish --dry-run",
                    "Verify gates + show order without uploading",
                ),
                (
                    "rok release <patch|minor|major>",
                    "Bump version + publish + GitHub release",
                ),
                (
                    "rok changelog",
                    "Preview unreleased commits grouped by type",
                ),
                ("rok key:generate", "Generate a random JWT secret"),
                ("rok key:rotate", "Rotate a key in .env"),
                (
                    "rok secrets:generate",
                    "Generate all secrets from .env.example",
                ),
                ("rok config:show", "Print current config values"),
                ("rok routes:list", "List all registered routes"),
                ("rok dev", "Start dev server with hot reload"),
                ("rok serve", "Start the application server"),
                ("rok env:check", "Check required env vars are set"),
                ("rok check", "Project health check"),
                ("rok list", "List all available commands"),
                ("rok completion <shell>", "Generate shell completions"),
                ("rok rok:init", "Create .rok/config.toml defaults"),
                ("rok tui", "Launch the terminal UI dashboard"),
            ],
        ),
    ];

    println!("{}", style("rok — available commands").bold().underlined());
    println!();

    for (group, commands) in &groups {
        println!("  {}:", style(group).cyan().bold());
        for (cmd, desc) in commands {
            println!("    {:<45} {}", style(cmd).green(), desc);
        }
        println!();
    }

    println!("  {}", style("Global flags:").bold());
    println!(
        "    {:<45} Output results as JSON",
        style("--json, -j").green(),
    );
    println!(
        "    {:<45} Print help for a command",
        style("--help, -h").green(),
    );
    println!("    {:<45} Print version", style("--version, -V").green(),);
}
