package com.pjilisense.flxai.wrapper;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class OffsetDateTimeSerializer extends JsonSerializer<OffsetDateTime> {
//    @Override
//    public void serialize(OffsetDateTimeWrapper value, SerializerProvider serializers, com.fasterxml.jackson.core.JsonGenerator gen) throws IOException {
//        gen.writeString(value.getDateTime().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
//    }

    @Override
    public void serialize(OffsetDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        LocalDateTime localDateTimeBJ=value.plusHours(8).toLocalDateTime();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        gen.writeString(localDateTimeBJ.format(formatter));
        //gen.writeString(value.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
    }
}
