/*
 * Copyright (c) 2004-2017, by Alex Leigh.
 * All rights reserved.
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE
 * The copyright notice above does not evidence any
 * actual or intended publication of such source code.
 */

package lc.mecha.util;

import lc.mecha.log.MechaLogger;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Constants used with UNIX/Windows processes (such as return values). This helps to standardize the behavior
 * of various executables.
 *
 * @author Alex Leigh
 */
public final class UniversalJob {
    // Return this value if the process received bad argumentation
    public static final int RET_OK = 0;
    public static final int RET_BADARGS = 2;
    public static final int RET_ERROR = 3;
    // Bad properties file
    public static final int RET_PROPS = 4;
    public static final int RET_BADENV = 5;

    private static String DEFAULT_COPYRIGHT = "2004-2023 Alex Leigh";

    /**
     * Output a standardized product startup / copyright notice to the
     * slf4j info channel.
     *
     * @param productName
     * @param copyrightEntity
     */
    public static void banner(final MechaLogger logger, final String productName, final String copyrightEntity) {
        logger.info(productName);
        logger.info("Copyright (c) {}. All Rights Reserved.", copyrightEntity);
    }

    public static void banner(final MechaLogger logger, final String productName) {
        banner(logger, productName, DEFAULT_COPYRIGHT);
    }

    /**
     * Formats and prints a usage message for the given CLI options to the given logger. The
     * formatting for the usage message will be offset by 30 characters, the amount necessary
     * for a default slf4j/log4j message.
     *
     * @param cmdLineSyntax
     * @param options
     */
    public static void printUsage(final MechaLogger logger, final String cmdLineSyntax, Options options) {
        final HelpFormatter formatter = new HelpFormatter();
        final StringWriter sw = new StringWriter();

        //  this.printHelp(pw, width, cmdLineSyntax, header, options, this.defaultLeftPad, this.defaultDescPad, footer, autoUsage);

        formatter.printHelp(new PrintWriter(sw), 80, cmdLineSyntax, null, options, 30, 0, null, false);
        logger.info(sw.toString());
    }
}