package stexfires.io.htmltable;

import stexfires.core.Record;
import stexfires.core.message.RecordMessage;
import stexfires.util.LineSeparator;

import java.nio.charset.Charset;
import java.nio.charset.CodingErrorAction;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author Mathias Kalb
 * @since 0.1
 */
public final class HtmlTableFileSpec {

    private final Charset charset;

    private final LineSeparator lineSeparator;
    private final String beforeTable;
    private final String afterTable;
    private final List<RecordMessage<Record>> recordMessages;
    private final CodingErrorAction codingErrorAction;

    @SafeVarargs
    public HtmlTableFileSpec(Charset charset, LineSeparator lineSeparator,
                             String beforeTable, String afterTable,
                             CodingErrorAction codingErrorAction,
                             RecordMessage<Record>... recordMessages) {
        Objects.requireNonNull(charset);
        Objects.requireNonNull(lineSeparator);
        Objects.requireNonNull(codingErrorAction);
        this.charset = charset;
        this.lineSeparator = lineSeparator;
        this.beforeTable = beforeTable;
        this.afterTable = afterTable;
        this.recordMessages = Collections.unmodifiableList(Arrays.asList(recordMessages));
        this.codingErrorAction = codingErrorAction;
    }

    public Charset getCharset() {
        return charset;
    }

    public LineSeparator getLineSeparator() {
        return lineSeparator;
    }

    public String getBeforeTable() {
        return beforeTable;
    }

    public String getAfterTable() {
        return afterTable;
    }

    public int recordMessagesSize() {
        return recordMessages.size();
    }

    public Stream<RecordMessage<Record>> streamOfRecordMessages() {
        return recordMessages.stream();
    }

    public CodingErrorAction getCodingErrorAction() {
        return codingErrorAction;
    }

}


@@ -215,16 +215,43 @@
 Action;%0A
+import java.nio.file.Path;%0A
 import j
@@ -474,36 +474,190 @@
    p
-rivate final Charset charset
+ublic static final CodingErrorAction DEFAULT_CODING_ERROR_ACTION = CodingErrorAction.REPORT;%0A%0A    private final Charset charset;%0A    private final CodingErrorAction codingErrorAction
 ;%0A%0A 
@@ -842,63 +842,8 @@
 ges;
-%0A    private final CodingErrorAction codingErrorAction;
 %0A%0A  
@@ -902,16 +902,82 @@
 charset,
+ CodingErrorAction codingErrorAction,%0A                            
  LineSep
@@ -1070,74 +1070,8 @@
 le,%0A
-                             CodingErrorAction codingErrorAction,%0A
     
@@ -1179,16 +1179,67 @@
 arset);%0A
+        Objects.requireNonNull(codingErrorAction);%0A
         
@@ -1308,33 +1308,30 @@
 NonNull(
-codingErrorAction
+recordMessages
 );%0A     
@@ -1353,24 +1353,76 @@
  = charset;%0A
+        this.codingErrorAction = codingErrorAction;%0A
         this
@@ -1630,119 +1630,1251 @@
     
+%7D%0A%0A
     
-this.codingErrorAction = codingErrorAction;%0A    %7D%0A%0A    public Charset getCharset() %7B%0A        return charset
+public static HtmlTableFileSpec write(Charset charset,%0A                                          LineSeparator lineSeparator,%0A                                          String beforeTable, String afterTable,%0A                                          RecordMessage%3CRecord%3E... recordMessages) %7B%0A        return new HtmlTableFileSpec(charset, DEFAULT_CODING_ERROR_ACTION,%0A                lineSeparator,%0A                beforeTable, afterTable,%0A                recordMessages);%0A    %7D%0A%0A    public static HtmlTableFileSpec write(Charset charset, CodingErrorAction codingErrorAction,%0A                                          LineSeparator lineSeparator,%0A                                          String beforeTable, String afterTable,%0A                                          RecordMessage%3CRecord%3E... recordMessages) %7B%0A        return new HtmlTableFileSpec(charset, codingErrorAction,%0A                lineSeparator,%0A                beforeTable, afterTable,%0A                recordMessages);%0A    %7D%0A%0A    public HtmlTableFile file(Path path) %7B%0A        return new HtmlTableFile(path, this);%0A    %7D%0A%0A    public Charset getCharset() %7B%0A        return charset;%0A    %7D%0A%0A    public CodingErrorAction getCodingErrorAction() %7B%0A        return codingErrorAction
 ;%0A  
@@ -3305,102 +3305,7 @@
  %7D%0A%0A
-    public CodingErrorAction getCodingErrorAction() %7B%0A        return codingErrorAction;%0A    %7D%0A%0A
 %7D%0A%0A

Refactor and enhance HtmlTableFileSpec