package com.izouma.nineth.utils;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.io.IOException;
import java.util.List;

public class PageDeserializer extends StdDeserializer<PageImpl> {

    public PageDeserializer() {
        super(PageImpl.class);
    }

    @Override
    public PageImpl deserialize(JsonParser p, DeserializationContext ctx) throws IOException, JacksonException {
        int number = ctx.readValue(p, int.class);
        int numberOfElements = ctx.readValue(p, int.class);
        long totalElements = ctx.readValue(p, long.class);
        long totalPages = ctx.readValue(p, long.class);
        int size = ctx.readValue(p, int.class);
        List content = ctx.readValue(p, List.class);
        new PageImpl<>(content, PageRequest.of(number, size), totalElements);
        return null;
    }


}