package org.bricolages.streaming.preflight;

import java.io.IOException;
import java.io.OutputStream;
import org.bricolages.streaming.s3.S3ObjectLocation;

import com.fasterxml.jackson.annotation.JsonProperty;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.*;

class LoadJobSerializer {
    private final OutputStream out;
    LoadJobSerializer(OutputStream out) {
        this.out = out;
    }
    
    void serialize(S3ObjectLocation dest, String ctFileName, String destTable) throws IOException {
        val jobDefinition = new LoadJobDefinition(dest.getKey(), ctFileName, destTable);
        val mapper = new ObjectMapper(new YAMLFactory());
        mapper.writeValue(out, jobDefinition);
    }

    @RequiredArgsConstructor
    @Getter
    @JsonNaming(PropertyNamingStrategy.KebabCaseStrategy.class)
    static class LoadJobDefinition {
        @JsonProperty("class")
        private String klass = "load";
        private String srcDs = "redshift-copy-buffer-preflight";
        private final String srcFile;
        private String destDs = "db_data";
        private final String tableDef;
        private final String destTable;
        private String format = "json";
        private boolean drop = true;
        private LoadJobOption option = new LoadJobOption();

        @Getter
        @JsonNaming(PropertyNamingStrategy.KebabCaseStrategy.class)
        static class LoadJobOption {
            private boolean gzip = true;
        }
    }
}
@@ -1442,24 +1442,25 @@
 ption option
+s
  = new LoadJ
@@ -1626,32 +1626,180 @@
 an gzip = true;%0A
+            private String timeformat = %22auto%22;%0A            private String dateformat = %22auto%22;%0A            private boolean truncatecolumns = true;%0A
         %7D%0A    %7D%0A
@@ -1799,8 +1799,9 @@
 %0A    %7D%0A%7D
+%0A

Fix bricolage load job options