package jnpf.model.culture.serializer;

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.LocalDate;
import java.time.ZoneId;

/**
 * LocalDate转换时间戳
 *
 * @author yanwenfu
 * @create 2026-01-04
 */
public class LocalDateToEpochSerializer extends JsonSerializer<LocalDate> {

    @Override
    public void serialize(
            LocalDate value,
            JsonGenerator gen,
            SerializerProvider serializers
    ) throws IOException {

        long epochMilli = value
                .atStartOfDay(ZoneId.systemDefault())
                .toInstant()
                .toEpochMilli();

        gen.writeNumber(epochMilli);
    }
}
