/*
 * Copyright 2014, Armenak Grigoryan, and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 */
package com.strider.datadefender;

import java.io.File;
import java.util.List;

import picocli.CommandLine.Option;

import lombok.Getter;

/**
 * Database configuration options for picocli.
 * 
 * @author Zaahid Bateson
 */
@Getter
public class ModelDiscoveryConfig {

    @Option(names = { "-l", "--limit" }, description = "Limit discovery to a set number of rows in a table", defaultValue = "1000")
    private Integer limit;

    @Option(names = { "-m", "--model" }, description = "Adds a built-in configured opennlp TokenizerME model for data discovery. "
                + "Available models are: ${AVAILABLE-MODELS}")
    private List<String> models;

    @Option(names = { "-e", "--extension" }, description = "Adds a call to an extension method "
        + "(e.g. com.strider.datadefender.specialcase.SinDetector.detectSin)")
    private List<String> extensions;

    @Option(names = { "--model-file" }, description = "Adds a custom made opennlp TokenizerME file for data discovery.")
    private List<File> fileModels;

    @Option(names = { "--token-model" }, description = "Override the default built-in token model (English tokens, "
        + "en-token.bin) with a custom token file for use by opennlp's TokenizerModel")
    private File tokenModel;

    @Option(names = { "--probability-threshold" }, description = "Minimum NLP match score to return results for", defaultValue = "0.55")
    private Double probabilityThreshold;

    @Option(names = { "--no-score-calculation" }, description = "If set, includes a column score", negatable = true)
    private Boolean calculateScore = false;

    @Option(names = { "--threshold-count" }, description = "Reports if number of rows found are greater than the defined threshold", defaultValue = "6")
    private Integer thresholdCount;

    @Option(names = { "--threshold-high" }, description = "Reports if number of high risk columns found are greater than the defined threshold", defaultValue = "3")
    private Integer thresholdHighRisk;
}

@@ -753,43 +753,207 @@
 ort 
-java.io.File;%0Aimport java.util.List
+com.strider.datadefender.discoverer.Discoverer;%0Aimport java.io.File;%0Aimport java.util.List;%0Aimport java.util.Optional;%0Aimport java.util.stream.Collectors;%0A%0Aimport org.apache.commons.lang3.StringUtils
 ;%0A%0Ai
@@ -1008,16 +1008,51 @@
 .Getter;
+%0Aimport lombok.extern.log4j.Log4j2;
 %0A%0A/**%0A *
@@ -1138,16 +1138,24 @@
 @Getter%0A
+@Log4j2%0A
 public c
@@ -1191,357 +1191,373 @@
     
-@Option(names = %7B %22-l%22, %22--limit%22 %7D, description = %22Limit discovery to a set number of rows in a table%22, defaultValue = %221000%22)%0A    private Integer limit;%0A%0A    @Option(names = %7B %22-m%22, %22--model%22 %7D, description = %22Adds a built-in configured opennlp TokenizerME model for data discovery. %22%0A                + %22Available models are: $%7BAVAILABLE-MODELS%7D%22)
+static %7B%0A        System.setProperty(%22AVAILABLE-MODELS%22, StringUtils.join(%0A            Discoverer.BUILT_IN_MODELS.keySet().stream().sorted().collect(Collectors.toList()),%0A            %22, %22%0A        ));%0A    %7D%0A%0A    @Option(names = %7B %22-l%22, %22--limit%22 %7D, description = %22Limit discovery to a set number of rows in a table%22, defaultValue = %221000%22)%0A    private Integer limit;%0A
 %0A   
@@ -2927,11 +2927,764 @@
 ighRisk;
+%0A%0A    @Option(names = %7B %22-m%22, %22--model%22 %7D, description = %22Adds a built-in configured opennlp TokenizerME model for data discovery. %22%0A                + %22Available models are: $%7BAVAILABLE-MODELS%7D%22)%0A    public void setModels(List%3CString%3E models) %7B%0A        Optional%3CString%3E unmatched = models.stream().filter((m) -%3E !Discoverer.BUILT_IN_MODELS.containsKey(m)).findFirst();%0A        if (unmatched.isPresent()) %7B%0A            log.error(%0A                %22A built-in model with the name %5C%22%7B%7D%5C%22 does not exist. Please specify one of: %7B%7D%22,%0A                unmatched.get(),%0A                System.getProperty(%22AVAILABLE-MODELS%22)%0A            );%0A            throw new IllegalArgumentException(%22Unmatched built-in model.%22);%0A        %7D%0A        this.models = models;%0A    %7D
 %0A%7D%0A

Add validation for built-in model names