"""Parser setup for the unified 'optimize' command.

Consolidates optimize-weights, optimize-steering, and optimize-classification
into a single command with subcommands.

Usage:
    wisent optimize weights --task coding --model Qwen/Qwen3-8B
    wisent optimize steering comprehensive Qwen/Qwen3-8B
    wisent optimize classification Qwen/Qwen3-8B
"""

import argparse
from wisent.core.parser_arguments.optimize_weights_parser import setup_optimize_weights_parser
from wisent.core.parser_arguments.optimize_steering_parser import setup_steering_optimizer_parser
from wisent.core.parser_arguments.optimize_classification_parser import setup_classification_optimizer_parser


def setup_optimize_parser(subparsers: argparse._SubParsersAction) -> None:
    """Set up the unified optimize command parser with subcommands."""
    
    optimize_parser = subparsers.add_parser(
        "optimize",
        help="Optimize model parameters (weights, steering, or classification)",
        description=(
            "Unified optimization command. Choose a method:\n"
            "  weights        - Optimize weight modification parameters\n"
            "  steering       - Optimize steering vector application\n"
            "  classification - Optimize classification thresholds"
        ),
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    
    # Create subparsers for the three optimization methods
    method_subparsers = optimize_parser.add_subparsers(
        dest="optimize_method",
        help="Optimization method to use",
        metavar="METHOD",
    )
    
    # Weights subcommand
    weights_parser = method_subparsers.add_parser(
        "weights",
        help="Optimize weight modification parameters",
        description="Optimize weight modification parameters for a given task.",
    )
    setup_optimize_weights_parser(weights_parser)
    
    # Steering subcommand
    steering_parser = method_subparsers.add_parser(
        "steering",
        help="Optimize steering vector application parameters",
        description="Optimize steering vector application parameters.",
    )
    setup_steering_optimizer_parser(steering_parser)
    
    # Classification subcommand
    classification_parser = method_subparsers.add_parser(
        "classification",
        help="Optimize classification thresholds",
        description="Optimize classification thresholds for a given model.",
    )
    setup_classification_optimizer_parser(classification_parser)
