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

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

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

import com.iqser.red.service.peristence.v1.server.integration.client.ApplicationConfigClient;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.ApplicationConfig;

public class ApplicationConfigTest extends AbstractPersistenceServerServiceTest {

    @Autowired
    private ApplicationConfigClient appConfigClient;


    @Test
    public void testAppConfig() {

        ApplicationConfig appConfig = new ApplicationConfig().builder()
                .downloadCleanupDownloadFilesHours(8)
                .downloadCleanupNotDownloadFilesHours(72)
                .softDeleteCleanupTime(96)
                .build();
        var result = appConfigClient.createOrUpdateAppConfig(appConfig);

        assertThat(result.getSoftDeleteCleanupTime()).isEqualTo(appConfig.getSoftDeleteCleanupTime());
        assertThat(result.getDownloadCleanupDownloadFilesHours()).isEqualTo(appConfig.getDownloadCleanupDownloadFilesHours());
        assertThat(result.getDownloadCleanupNotDownloadFilesHours()).isEqualTo(appConfig.getDownloadCleanupNotDownloadFilesHours());
        var getResult = appConfigClient.getCurrentApplicationConfig();
        assertThat(getResult.getSoftDeleteCleanupTime()).isEqualTo(appConfig.getSoftDeleteCleanupTime());
        assertThat(getResult.getDownloadCleanupDownloadFilesHours()).isEqualTo(appConfig.getDownloadCleanupDownloadFilesHours());
        assertThat(getResult.getDownloadCleanupNotDownloadFilesHours()).isEqualTo(appConfig.getDownloadCleanupNotDownloadFilesHours());

        appConfig.setDownloadCleanupDownloadFilesHours(16);
        appConfig.setDownloadCleanupNotDownloadFilesHours(80);
        appConfig.setSoftDeleteCleanupTime(100);

        appConfigClient.createOrUpdateAppConfig(appConfig);
        getResult = appConfigClient.getCurrentApplicationConfig();
        assertThat(getResult.getSoftDeleteCleanupTime()).isEqualTo(appConfig.getSoftDeleteCleanupTime());
        assertThat(getResult.getDownloadCleanupDownloadFilesHours()).isEqualTo(appConfig.getDownloadCleanupDownloadFilesHours());
        assertThat(getResult.getDownloadCleanupNotDownloadFilesHours()).isEqualTo(appConfig.getDownloadCleanupNotDownloadFilesHours());
    }

}
