package com.iqser.red.service.peristence.v1.server.integration.tests;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.management.v1.processor.model.AnalysisFlags;
import com.iqser.red.service.persistence.management.v1.processor.service.AnalysisFlagsCalculationService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.WorkflowStatus;

import io.swagger.v3.core.util.ObjectMapperFactory;

public class AnalysisFlagCalculationServiceTest extends AbstractPersistenceServerServiceTest {

    @Autowired
    private AnalysisFlagsCalculationService analysisFlagsCalculationService;


    @Test
    public void testWithEntityLogContainingOnlyImages() throws IOException {

        var file = new ClassPathResource(String.format("files/entity-log/entitylog-only-images.json"));
        ObjectMapper objectMapper = ObjectMapperFactory.buildStrictGenericObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());

        EntityLog entityLog = objectMapper.readValue(file.getInputStream(), EntityLog.class);

        var data = new AnalysisFlagsCalculationService.FlagCalculationData(FileEntity.builder().workflowStatus(WorkflowStatus.UNDER_REVIEW).build(),
                                                                           entityLog,
                                                                           Map.of(1, OffsetDateTime.now()));
        AnalysisFlags analysisFlags = analysisFlagsCalculationService.calculateFlags(data);

        assertTrue(analysisFlags.hasRedactions());
    }

}
