/*                          ----------------------
 *                                 voltdivx
 *                          ----------------------
 *                       Copyright(c)2015 Jonas Sjöberg
 *                       https://github.com/jonasjberg
 *                            jomeganas@gmail.com
 *______________________________________________________________________________
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *                    (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *______________________________________________________________________________
 */

package com.jonasjberg.voltdivx.arguments;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

/**
 * Created by spock on 2016-01-11.
 */
public class ArgumentOptions
{
    public static Options options;

    private ArgumentOptions() {}     // Prevents instantiation
                                     // (Effective Java, 2nd Edition. Page 99.)

    public static Options getOptions()
    {
        if (options == null)
            options = constructOptions();

        return options;
    }

    private static Options constructOptions()
    {
        final Options options = new Options();

        Option input    = Option.builder("i").longOpt("Vin")
                                .desc("input voltage in volts")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("VOLTS")
                                .build();

        Option output   = Option.builder("o").longOpt("Vout")
                                .desc("output voltage in volts")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("VOLTS")
                                .build();

        Option ground   = Option.builder("g").longOpt("ground")
                                .desc("ground potential voltage in volts."
                                      + "(Defaults to 0V)")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("VOLTS")
                                .build();

        Option r1       = Option.builder("r").longOpt("R1")
                                .desc("R1 resistance in ohms (top of divider)")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1)
                                .argName("OHMS").build();

        Option r2       = Option.builder("t").longOpt("R2")
                                .desc("R2 resistance in ohms (bottom of divider)")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1)
                                .argName("OHMS").build();

        Option series   = Option.builder("s").longOpt("value-series")
                                .desc("Series of standard \"E\"-values. "
                                      + "Where SERIES is E6, E12, E24, E48, E96 or E192.")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("SERIES")
                                .build();

        Option maxError = Option.builder("e").longOpt("max-error")
                                .desc("Maximum allowed error")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("VOLTS")
                                .build();

        Option lines    = Option.builder("l").longOpt("lines")
                                .desc("Number of lines to display")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("LINES")
                                .build();

        Option maxCurr  = Option.builder("c").longOpt("max-current")
                                .desc("Maximum allowed maxCurrent")
                                .required(false).optionalArg(false)
                                .hasArg().numberOfArgs(1).argName("AMPS")
                                .build();

        Option quiet    = Option.builder("q").longOpt("quiet")
                                .desc("Be less verbose. Output results for easier parsing.")
                                .required(false)
                                .build();

        Option help     = Option.builder("h").longOpt("help")
                                .desc("display help")
                                .required(false)
                                .build();

        options.addOption(help);
        options.addOption(input);
        options.addOption(output);
        options.addOption(ground);
        options.addOption(r1);
        options.addOption(r2);
        options.addOption(series);
        options.addOption(maxError);
        options.addOption(lines);
        options.addOption(maxCurr);
        options.addOption(quiet);

        return options;
    }
}
