package com.knecon.fforesight.service.layoutparser.server.model;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

import org.apache.pdfbox.util.Matrix;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.storage.commons.properties.StorageProperties;
import com.iqser.red.storage.commons.service.ObjectSerializer;
import com.knecon.fforesight.service.layoutparser.processor.model.text.TextDirection;
import com.knecon.fforesight.service.layoutparser.processor.model.text.TextPositionSequence;

import lombok.SneakyThrows;

public class TextPositionSequenceTest {

    private static final String TEXT_POSITION_SEQUENCE_AS_JSON = "{\n" //
            + "  \"page\": 1,\n" //
            + "  \"textPositions\": [],\n" //
            + "  \"dir\": 180.0,\n" //
            + "  \"rotation\": 0,\n" //
            + "  \"pageHeight\": 800,\n" //
            + "  \"pageWidth\": 600\n"  //
            + "}";

    private final ObjectSerializer objectSerializer = new ObjectSerializer(new ObjectMapper());


    @Test
    @SneakyThrows
    public void testDeserializationWithJackson() {

        TextPositionSequence textPositionSequence = objectSerializer.deserialize(new ByteArrayInputStream(TEXT_POSITION_SEQUENCE_AS_JSON.getBytes(StandardCharsets.UTF_8)),
                TextPositionSequence.class);

        assertPropertiesAfterJsonDeserialization(textPositionSequence);
    }


    private void assertPropertiesAfterJsonDeserialization(TextPositionSequence textPositionSequence) {

        assertThat(textPositionSequence.getPage()).isEqualTo(1);
        assertThat(textPositionSequence.getTextPositions()).hasSize(0);
        assertThat(textPositionSequence.getDir()).isEqualTo(TextDirection.HALF_CIRCLE);
        assertThat(textPositionSequence.getRotation()).isEqualTo(0);
        assertThat(textPositionSequence.getPageHeight()).isEqualTo(800f);
        assertThat(textPositionSequence.getPageWidth()).isEqualTo(600f);
    }


    private Matrix createIdentityMatrix() {

        return new Matrix();
    }

}