package com.njcn.product.event.config;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

/**
 * @Author: cdf
 * @CreateTime: 2025-07-25
 * @Description:
 */
@Component
public class RedisInstantDateDeserializer extends StdDeserializer<Instant> {

    public RedisInstantDateDeserializer() {
        this(null);
    }


    protected RedisInstantDateDeserializer(Class<?> vc) {
        super(vc);
    }


    @Override
    public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String text = p.getValueAsString();
        return DateUtil.parse(text, DatePattern.NORM_DATETIME_PATTERN).toInstant().plusMillis(TimeUnit.HOURS.toMillis(8));
    }
}
