// Path: src/main/java/ninja/javafx/smartcsv/FileReader.java
// public interface FileReader<E> {
//     E getContent();
//     void read(File filename) throws IOException;
// }
// 
// Path: src/main/java/ninja/javafx/smartcsv/validation/configuration/Field.java
// public class Field {
// 
//     private String name;
//     private String title;
//     private Type type;
//     private String description;
//     private String format;
//     private Object missingValue;
//     private Constraints constraints;
//     private String groovy;
// 
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(String title) {
//         this.title = title;
//     }
// 
//     public Type getType() {
//         return type;
//     }
// 
//     public void setType(Type type) {
//         this.type = type;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public void setDescription(String description) {
//         this.description = description;
//     }
// 
//     public String getFormat() {
//         return format;
//     }
// 
//     public void setFormat(String format) {
//         this.format = format;
//     }
// 
//     public Object getMissingValue() {
//         return missingValue;
//     }
// 
//     public void setMissingValue(Object missingValue) {
//         this.missingValue = missingValue;
//     }
// 
//     public Constraints getConstraints() {
//         return constraints;
//     }
// 
//     public void setConstraints(Constraints constraints) {
//         this.constraints = constraints;
//     }
// 
//     public String getGroovy() {
//         return groovy;
//     }
// 
//     public void setGroovy(String groovy) {
//         this.groovy = groovy;
//     }
// 
// }
// 
// Path: src/main/java/ninja/javafx/smartcsv/validation/configuration/ValidationConfiguration.java
// public class ValidationConfiguration {
// 
//     @SerializedName("fields")
//     private Field[] fields;
// 
//     public Field[] getFields() {
//         return fields;
//     }
// 
//     public void setFields(Field[] fields) {
//         this.fields = fields;
//     }
// 
//     public Field getFieldConfiguration(String column) {
//         for (Field field : fields) {
//             if (field.getName().equals(column)) {
//                 return field;
//             }
//         }
//         return null;
//     }
// 
//     public String[] headerNames() {
//         if (fields != null) {
//             List<String> headerNames = new ArrayList<>();
//             for (Field field : fields) {
//                 headerNames.add(field.getName());
//             }
//             return headerNames.toArray(new String[headerNames.size()]);
//         }
// 
//         return null;
//     }
// 
//     public void setHeaderNames(String[] header) {
//         fields = new Field[header.length];
//         int i = 0;
//         for (String headerName: header) {
//             fields[i] = new Field();
//             fields[i].setName(headerName);
//             i++;
//         }
//     }
// }
// 
// Path: src/main/java/ninja/javafx/smartcsv/validation/configuration/Type.java
// public enum Type {
//     @SerializedName("string")STRING,
//     @SerializedName("integer")INTEGER,
//     @SerializedName("number")NUMBER,
//     @SerializedName("date")DATE,
//     @SerializedName("datetime")DATETIME,
//     @SerializedName("time")TIME
// // TODO: currently not supported
// //        @SerializedName("object") OBJECT,
// //        @SerializedName("array") ARRAY,
// //        @SerializedName("duration") DURATION,
// //        @SerializedName("geopoint") GEOPOINT,
// //        @SerializedName("geojson") GEOJSON
// }


import java.io.File;
import java.io.IOException;
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.FileReader;
import ninja.javafx.smartcsv.validation.configuration.Field;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
/*
   The MIT License (MIT)
   -----------------------------------------------------------------------------

   Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.

*/

package ninja.javafx.smartcsv.validation;




/**
 * This class loads the constraints as json config
 */
public class ValidationFileReader implements FileReader<ValidationConfiguration> {

    private ValidationConfiguration config;

    @Override
    public void read(File file) throws IOException {
        config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
        setDefaults();
    }

    private void setDefaults() {
// Path: src/main/java/ninja/javafx/smartcsv/FileReader.java
// public interface FileReader<E> {
//     E getContent();
//     void read(File filename) throws IOException;
// }
// 
// Path: src/main/java/ninja/javafx/smartcsv/validation/configuration/Field.java
// public class Field {
// 
//     private String name;
//     private String title;
//     private Type type;
//     private String description;
//     private String format;
//     private Object missingValue;
//     private Constraints constraints;
//     private String groovy;
// 
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(String title) {
//         this.title = title;
//     }
// 
//     public Type getType() {
//         return type;
//     }
// 
//     public void setType(Type type) {
//         this.type = type;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public void setDescription(String description) {
//         this.description = description;
//     }
// 
//     public String getFormat() {
//         return format;
//     }
// 
//     public void setFormat(String format) {
//         this.format = format;
//     }
// 
//     public Object getMissingValue() {
//         return missingValue;
//     }
// 
//     public void setMissingValue(Object missingValue) {
//         this.missingValue = missingValue;
//     }
// 
//     public Constraints getConstraints() {
//         return constraints;
//     }
// 
//     public void setConstraints(Constraints constraints) {
//         this.constraints = constraints;
//     }
// 
//     public String getGroovy() {
//         return groovy;
//     }
// 
//     public void setGroovy(String groovy) {
//         this.groovy = groovy;
//     }
// 
// }
// 
// Path: src/main/java/ninja/javafx/smartcsv/validation/configuration/ValidationConfiguration.java
// public class ValidationConfiguration {
// 
//     @SerializedName("fields")
//     private Field[] fields;
// 
//     public Field[] getFields() {
//         return fields;
//     }
// 
//     public void setFields(Field[] fields) {
//         this.fields = fields;
//     }
// 
//     public Field getFieldConfiguration(String column) {
//         for (Field field : fields) {
//             if (field.getName().equals(column)) {
//                 return field;
//             }
//         }
//         return null;
//     }
// 
//     public String[] headerNames() {
//         if (fields != null) {
//             List<String> headerNames = new ArrayList<>();
//             for (Field field : fields) {
//                 headerNames.add(field.getName());
//             }
//             return headerNames.toArray(new String[headerNames.size()]);
//         }
// 
//         return null;
//     }
// 
//     public void setHeaderNames(String[] header) {
//         fields = new Field[header.length];
//         int i = 0;
//         for (String headerName: header) {
//             fields[i] = new Field();
//             fields[i].setName(headerName);
//             i++;
//         }
//     }
// }
// 
// Path: src/main/java/ninja/javafx/smartcsv/validation/configuration/Type.java
// public enum Type {
//     @SerializedName("string")STRING,
//     @SerializedName("integer")INTEGER,
//     @SerializedName("number")NUMBER,
//     @SerializedName("date")DATE,
//     @SerializedName("datetime")DATETIME,
//     @SerializedName("time")TIME
// // TODO: currently not supported
// //        @SerializedName("object") OBJECT,
// //        @SerializedName("array") ARRAY,
// //        @SerializedName("duration") DURATION,
// //        @SerializedName("geopoint") GEOPOINT,
// //        @SerializedName("geojson") GEOJSON
// }


// Path: src/main/java/ninja/javafx/smartcsv/validation/ValidationFileReader.java
import java.io.File;
import java.io.IOException;
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.FileReader;
import ninja.javafx.smartcsv.validation.configuration.Field;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;

/*
   The MIT License (MIT)
   -----------------------------------------------------------------------------

   Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.

*/

package ninja.javafx.smartcsv.validation;




/**
 * This class loads the constraints as json config
 */
public class ValidationFileReader implements FileReader<ValidationConfiguration> {

    private ValidationConfiguration config;

    @Override
    public void read(File file) throws IOException {
        config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
        setDefaults();
    }

    private void setDefaults() {
        for (Field field : config.getFields()) {