package fr.umlv.poo.optparser.main;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;

import fr.umlv.poo.optparser.OptionParser;

public class Main {
  public static void main(String[] args) {
    HashMap<String, Object> options = new HashMap<>();
    OptionParser optionParser = OptionParser.create(opts -> {
        // Set a banner, displayed at the top
        // of the help screen.
        opts.setBanner("Usage: Main [options] file1 file2 ...");
      
        // Define the options, and what they do
        options.put("verbose", false);
        opts.on("-v", "--verbose", "Output more information", () -> {
          options.put("verbose", true);
        });
      
        options.put("quick", false);
        opts.on("-q", "--quick", "Perform the task quickly", () -> {
          options.put("quick", true);
        });
      
        /*options.put("logfile", null);
        opts.on("-l", "--logfile FILE", Path.class, "Write log to FILE", path -> {
          options.put("logfile", path);
        });*/
      
        // This displays the help screen, all programs are
        // assumed to have this option.
        opts.on("-h", "--help", "Display this screen", () -> {
          System.err.println(opts);
          System.exit(1);
        });
    });
    
    // Parse the command-line and returns a list of arguments
    // that are not options
    List<String> arguments = optionParser.parse(args);
    
    System.out.println("Being verbose " + options.get("verbose"));
    System.out.println("Being quick " + options.get("quick"));
    System.out.println("Logging to file " + options.get("logfile"));
    
    arguments.forEach(file -> {
      System.out.printf("Resizing image %s...", file);
    });
  }
}
