package org.dbflute.intro.app.web.document.decomment;

import java.util.List;
import java.util.stream.Collectors;

import org.dbflute.intro.app.model.document.decomment.parts.DfDecoMapColumnPart;
import org.dbflute.intro.app.model.document.decomment.parts.DfDecoMapTablePart;
import org.lastaflute.web.validation.Required;

/**
 * @author hakiba
 * @author jflute
 */
public class DecommentPickupResult {

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
    @Required
    public List<TablePart> tables;

    // done hakiba move it under tables by jflute (2017/08/17)
    // done hakiba validator annotation (Required only) by jflute (2017/08/17)
    public static class TablePart {
        @Required
        public String tableName;
        @Required
        public List<ColumnPart> columns;

        public TablePart(DfDecoMapTablePart tablePart) {
            this.tableName = tablePart.getTableName();
            this.columns = tablePart.getColumns().stream().map(columnPart -> new ColumnPart(columnPart)).collect(Collectors.toList());
        }

        public static class ColumnPart {
            @Required
            public String columnName;
            @Required
            public List<PropertyPart> properties;

            public ColumnPart(DfDecoMapColumnPart columnPart) {
                this.columnName = columnPart.getColumnName();
                this.properties =
                        columnPart.getProperties().stream().map(property -> new PropertyPart(property)).collect(Collectors.toList());
            }

            // done hakiba PropertyPart by jflute (2017/08/17)
            public static class PropertyPart {
                @Required
                public String decomment;
                @Required
                public String databaseComment;
                @Required
                public String previousWholeComment;
                @Required
                public Long commentVersion;
                @Required
                public List<String> authorList;

                public PropertyPart(DfDecoMapColumnPart.ColumnPropertyPart property) {
                    this.decomment = property.getDecomment();
                    this.databaseComment = property.getDatabaseComment();
                    this.previousWholeComment = property.getPreviousWholeComment();
                    this.commentVersion = property.getCommentVersion();
                    this.authorList = property.getAuthorList();
                }
            }
        }
    }

    // ===================================================================================
    //                                                                         Constructor
    //                                                                         ===========
    public DecommentPickupResult(List<DfDecoMapTablePart> tableParts) {
        this.tables = tableParts.stream().map(tablePart -> new TablePart(tablePart)).collect(Collectors.toList());
    }
}

@@ -108,16 +108,48 @@
 ctors;%0A%0A
+import javax.validation.Valid;%0A%0A
 import o
@@ -217,24 +217,24 @@
 ColumnPart;%0A
-
 import org.d
@@ -389,16 +389,33 @@
  jflute%0A
+ * @author cabos%0A
  */%0Apubl
@@ -717,24 +717,35 @@
   =========%0A
+    @Valid%0A
     @Require
@@ -1007,24 +1007,39 @@
  tableName;%0A
+        @Valid%0A
         @Req
@@ -1441,24 +1441,43 @@
 columnName;%0A
+            @Valid%0A
             
@@ -1697,20 +1697,16 @@
 rties =%0A
-    
         
@@ -1819,32 +1819,32 @@
 tors.toList());%0A
+
             %7D%0A%0A 
@@ -2188,32 +2188,32 @@
       @Required%0A
-
                 
@@ -2240,16 +2240,39 @@
 ersion;%0A
+                @Valid%0A
         

add "@Valid" to DecommentPickupResult's field