//! Command-line help and version output utilities.
//!
//! This module provides functions to print usage instructions,
//! available image processing commands, version information, and help
//! for specific options such as luminance formulas or character sets.

use crate::defines::{
    DEBUG_IMAGE_NAME, IGNORE_PIXELS, MIN_CHAR_H, MIN_CHAR_W, MIN_SEGMENT, NEED_PIXELS,
    NUMBER_OF_DIGITS, THRESHOLD, VERSION,
};

/// Prints the help details for available luminance calculation keywords.
pub fn print_lum_help() {
    println!("rec601    use gamma corrected RGB values according to ITU-R Rec. BT.601-4");
    println!("rec709    use linear RGB values according to ITU-R Rec. BT.709");
    println!("linear    use (R+G+B)/3 as done by cvtool 0.0.1");
    println!("minimum   use min(R,G,B) as done by GNU Ocrad 0.14");
    println!("maximum   use max(R,G,B)");
    println!("red       use R value");
    println!("green     use G value");
    println!("blue      use B value");
}

/// Prints the help details for supported character sets (keywords).
pub fn print_cs_help() {
    println!("full      all characters supported by ssocr");
    println!("digits    digits 0 to 9");
    println!("decimal   digits 0 to 9, decimal point, minus");
    println!("hex       digits 0 to f, decimal point, minus");
    println!("tt_robot  digits and characters used by a Chinese table tennis robot");
}

/// Prints the program version and copyright information to stdout.
pub fn print_version() {
    println!(
        "Seven Segment Optical Character Recognition Version {}",
        VERSION
    );
    println!("Copyright (C) 2004-2025 Erik Auerswald <auerswal@unix-ag.uni-kl.de>");
    println!("This program comes with ABSOLUTELY NO WARRANTY.");
    println!("This is free software, and you are welcome to redistribute it");
    println!("under the terms of the GNU GPL (version 3 or later).");
}

/// Prints a short usage summary for the program.
///
/// # Arguments
/// * `name` - The executable name.
pub fn print_short_usage(name: &str) {
    println!("\nUsage: {} [OPTION]... [COMMAND]... IMAGE", name);
    println!(
        "Use '{} --help' to print long help describing all options",
        name
    );
}

/// Prints the full, detailed command-line interface help message.
///
/// # Arguments
/// * `name` - The executable name.
pub fn print_help(name: &str) {
    print_version();
    println!("\nUsage: {} [OPTION]... [COMMAND]... IMAGE", name);
    println!("\nOptions: -h, --help               print this message");
    println!("         -v, --verbose            talk about program execution");
    println!("         -V, --version            print version information");
    println!("         -t, --threshold=THRESH   use THRESH (in percent) to distinguish black");
    println!("                                  from white");
    println!("         -a, --absolute-threshold don't adjust threshold to image");
    println!("         -T, --iter-threshold     use iterative thresholding method");
    println!("         -n, --number-pixels=#    number of pixels needed to recognize a segment");
    println!("         -N, --min-segment=SIZE   minimum width and height of a segment");
    println!("         -i, --ignore-pixels=#    number of pixels ignored when searching digit");
    println!("                                  boundaries");
    println!("         -M, --min-char-dims=WxH  minimum width and height of a character/digit");
    println!("         -d, --number-digits=RNG  number of digits in image (-1 for auto,");
    println!("                                  positive number, or positive range)");
    println!("         -r, --one-ratio=#        height/width ratio to recognize a 'one'");
    println!("         -m, --minus-ratio=#      width/height ratio to recognize a minus sign");
    println!("         -H, --dec-h-ratio=#      max_dig_h/h ratio to recognize decimal point");
    println!("         -W, --dec-w-ratio=#      max_dig_w/w ratio to recognize decimal point");
    println!("         -o, --output-image=FILE  write processed image to FILE");
    println!("         -O, --output-format=FMT  use output format FMT");
    println!("         -p, --process-only       do image processing only, no OCR");
    println!(
        "         -D, --debug-image[=FILE] write a debug image to FILE or {}",
        DEBUG_IMAGE_NAME
    );
    println!("         -P, --debug-output       print debug information");
    println!("         -f, --foreground=COLOR   set foreground color (black or white)");
    println!("         -b, --background=COLOR   set background color (black or white)");
    println!("         -I, --print-info         print image dimensions and used lum values");
    println!("         -g, --adjust-gray        use T1 and T2 from gray_stretch as");
    println!("                                  percentages of used values");
    println!("         -l, --luminance=KEYWORD  compute luminance using formula KEYWORD");
    println!("                                  use -l help for list of KEYWORDS");
    println!("         -s, --print-spaces       print spaces between more distant digits");
    println!("         -A, --space-factor=FAC   relative distance to add spaces");
    println!("         -G, --space-average      use average instead of minimum distance");
    println!("                                  to determine spaces between digits");
    println!("         -S, --ascii-art-segments print recognized segments a ASCII art");
    println!("         -X, --print-as-hex       change output format to hexadecimal");
    println!("         -C, --omit-decimal-point omit decimal points from output");
    println!("         -c, --charset=KEYWORD    select recognized characters");
    println!("                                  use -c help for list of KEYWORDS");
    println!("         -F, --adapt-after-crop   do not adapt threshold to image directly");
    println!("                                  before, only after, cropping");
    println!("\nCommands: dilation [N]            [N times] dilation algorithm");
    println!("                                  (set_pixels_filter with mask of 1 pixel)");
    println!("          erosion [N]             [N times] erosion algorithm");
    println!("                                  (set_pixels_filter with mask of 9 pixels)");
    println!("          closing [N]             closing algorithm");
    println!("                                  ([N times] dilation then [N times] erosion)");
    println!("          opening [N]             opening algorithm");
    println!("                                  ([N times] erosion then [N times] dilation)");
    println!("          remove_isolated         remove isolated pixels");
    println!("          make_mono               make image monochrome");
    println!("          grayscale               transform image to grayscale");
    println!("          invert                  make inverted monochrome image");
    println!("          gray_stretch T1 T2      stretch luminance values from [T1,T2] to");
    println!("                                  [0,255] (use --adjust-gray for percentages)");
    println!("          dynamic_threshold W H   make image monochrome w. dynamic thresholding");
    println!("                                  with a window of width W and height H");
    println!("          rgb_threshold           make image monochrome by setting every pixel");
    println!("                                  with any values of red, green or blue below");
    println!("                                  the threshold to black");
    println!("          r_threshold             make image monochrome using only red channel");
    println!("          g_threshold             make image monochrome using only green channel");
    println!("          b_threshold             make image monochrome using only blue channel");
    println!("          white_border [WIDTH]    make border of WIDTH (or 1) in background");
    println!("                                  color");
    println!("          shear OFFSET            shear image OFFSET pixels (at bottom) to the");
    println!("                                  right");
    println!("          rotate THETA            rotate image clockwise by THETA degrees");
    println!("          mirror {{horiz|vert}}     mirror image horizontally or vertically");
    println!("          crop X Y W H            crop image with upper left corner (X,Y) with");
    println!("                                  width W and height H");
    println!("          set_pixels_filter MASK  set pixels that have at least MASK neighbor");
    println!("                                  pixels set (including checked position)");
    println!("          keep_pixels_filter MASK keeps pixels that have at least MASK neighbor");
    println!("                                  pixels set (not counting the checked pixel)");
    println!(
        "\nDefaults: needed pixels                         = {:2}",
        NEED_PIXELS
    );
    println!(
        "          minimum segment size                  = {:2}",
        MIN_SEGMENT
    );
    println!(
        "          minimum character width               = {:2}",
        MIN_CHAR_W
    );
    println!(
        "          minimum character height              = {:2}",
        MIN_CHAR_H
    );
    println!(
        "          ignored pixels                        = {:2}",
        IGNORE_PIXELS
    );
    println!(
        "          minimum number of digits              = {:2}",
        NUMBER_OF_DIGITS
    );
    println!(
        "          maximum number of digits              = {:2}",
        NUMBER_OF_DIGITS
    );
    println!(
        "          threshold                             = {:5.2}",
        THRESHOLD
    );
    println!("          foreground                            = black");
    println!("          background                            = white");
}
