/**
 * Copyright (c) 2016, German Neuroinformatics Node (G-Node)
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted under the terms of the BSD License. See
 * LICENSE file in the root of the Project.
 */

package org.g_node.reporter.LKTLogbook;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.g_node.micro.commons.CliToolController;

/**
 * Class handling how to fetch reports from an RDF file specific to the LKT Logbook use case of Kay Thurley.
   *
 * @author Michael Sonntag (sonntag@bio.lmu.de)
 */
public class CliLKTController implements CliToolController {
    /**
     * Method returning the commandline options of the LKT reporter tool.
     *
     * @return Available {@link CommandLine} {@link Options}.
     */
    public final Options options() {

        final Options options = new Options();

        final Option opHelp = new Option("h", "help", false, "Print this message.");

        final String inDesc = String.join("",
                "RDF file containing the main database. ",
                "Data for the required report will be fetched from this file.");

        final Option opInRdfFile = Option.builder("i")
                .longOpt("input-rdf")
                .desc(inDesc)
                .required()
                .hasArg()
                .valueSeparator()
                .build();

        // TODO implement available reports
        final String reportDesc = String.join("",
                "Reports available to the selected tool.");

        final Option opReport = Option.builder("r")
                .longOpt("report")
                .desc(reportDesc)
                .required()
                .hasArg()
                .valueSeparator()
                .build();

        final String outDesc = String.join("",
                "Optional: Path and name of the output file. ",
                "Files with the same name will be overwritten. ");

        final Option opOut = Option.builder("o")
                .longOpt("out-file")
                .desc(outDesc)
                .hasArg()
                .valueSeparator()
                .build();

        final String formatDesc = String.join("",
                "Optional: format of the report file that will be written.\n",
                "\nDefault setting is the CSV format.");

        final Option opFormat = Option.builder("f")
                .longOpt("out-format")
                .desc(formatDesc)
                .hasArg()
                .valueSeparator()
                .build();

        options.addOption(opHelp);
        options.addOption(opInRdfFile);
        options.addOption(opReport);
        options.addOption(opOut);
        options.addOption(opFormat);

        return options;
    }

    /**
     * Method to check input file, available report, output file format and to facilitate the
     * delegation of creating the report and saving it an output file.
     *
     * @param cmd User provided {@link CommandLine} input.
     */
    public final void run(final CommandLine cmd) {
        System.out.println("Implement checks and actual call of reports.");
    }

}

@@ -319,16 +319,69 @@
 gbook;%0A%0A
+import java.util.Collections;%0Aimport java.util.List;%0A
 import o
@@ -542,16 +542,56 @@
 troller;
+%0Aimport org.g_node.srv.CliOptionService;
 %0A%0A/**%0A *
@@ -1024,555 +1024,116 @@
     
-final Options options = new Options();%0A%0A        final Option opHelp = new Option(%22h%22, %22help%22, false, %22Print this message.%22);%0A%0A        final String inDesc = String.join(%22%22,%0A                %22RDF file containing the main database. %22,%0A                %22Data for the required report will be fetched from this file.%22);%0A%0A        final Option opInRdfFile = Option.builder(%22i%22)%0A                .longOpt(%22input-rdf%22)%0A                .desc(inDesc)%0A                .required()%0A                .hasArg()%0A                .valueSeparator()%0A                .build(
+// TODO implement available reports%0A        final List%3CString%3E reports = Collections.singletonList(%22default%22
 );%0A%0A
@@ -1160,37 +1160,44 @@
 ement available 
-repor
+output forma
 ts%0A        final
@@ -1201,100 +1201,61 @@
 nal 
+List%3C
 String
- reportDesc = String.join(%22%22,%0A                %22Reports availab
+%3E formats = Collections.sing
 le
- 
 to
- the selected tool.
+nList(%22CSV
 %22);%0A
@@ -1279,224 +1279,102 @@
 tion
+s
  op
-Report = Option.builder(%22r%22)%0A                .longOpt(%22report%22)%0A                .desc(reportDesc)%0A                .required()%0A                .hasArg()%0A                .valueSeparator()%0A                .build(
+tions = new Options();%0A%0A        final Option opHelp = CliOptionService.getHelpOption(%22%22
 );%0A
-%0A
     
@@ -1387,173 +1387,67 @@
 nal 
-String outDesc = String.join(%22%22,%0A                %22Optional: Path and name of the output file. %22,%0A                %22Files with the same name will be overwritten. 
+Option opInRdfFile = CliOptionService.getInFileOption(%22
 %22);%0A
-%0A
     
@@ -1469,189 +1469,64 @@
 n op
-Ou
+Repor
 t = 
+Cli
 Option
-.builder(%22o%22)%0A                .longOpt(%22out-file%22)%0A                .desc(outDesc)%0A                .hasArg()%0A                .valueSeparator()%0A                .build(
+Service.getReportOption(%22%22, reports
 );%0A
-%0A
     
@@ -1539,181 +1539,66 @@
 nal 
-String formatDesc = String.join(%22%22,%0A                %22Optional: format of the report file that will be written.%5Cn%22,%0A                %22%5CnDefault setting is the CSV format.
+Option opOutFile = CliOptionService.getOutFileOption(%22
 %22);%0A
-%0A
     
@@ -1616,16 +1616,19 @@
 ption op
+Out
 Format =
@@ -1632,184 +1632,55 @@
 t = 
+Cli
 Option
-.builder(%22f%22)%0A                .longOpt(%22out-format%22)%0A                .desc(formatDesc)%0A                .hasArg()%0A                .valueSeparator()%0A                .build(
+Service.getOutFormatOption(%22%22, formats
 );%0A%0A
@@ -1822,16 +1822,20 @@
 on(opOut
+File
 );%0A     
@@ -1857,16 +1857,19 @@
 ption(op
+Out
 Format);

use common CLI options