package fr.insee.rmes.api.operations;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

import fr.insee.rmes.api.AbstractApiTest;
import fr.insee.rmes.modeles.operations.Famille;
import fr.insee.rmes.modeles.operations.FamilyToOperation;

@ExtendWith(MockitoExtension.class)
public class OperationsApiServiceTest extends AbstractApiTest {

    @InjectMocks
    private OperationsApiService operationsApiService;

    private List<FamilyToOperation> opList = new ArrayList<>();
    private Map<String, Famille> familyMap = new HashMap<>();

    @Test
    public void givenGetListeFamilyToOperation_whenListIsEmpty() {
        Assertions.assertEquals(familyMap, operationsApiService.getListeFamilyToOperation(opList));
    }

    private FamilyToOperation getAFamilyToOperation(String someValue) {
        FamilyToOperation familyToOperation = new FamilyToOperation();
        familyToOperation.setSeries(someValue);
        familyToOperation.setSeriesId(someValue);
        familyToOperation.setSeriesLabelLg1(someValue);
        familyToOperation.setSeriesLabelLg2(someValue);
        familyToOperation.setSeriesAltLabelLg1(someValue);
        familyToOperation.setSeriesAltLabelLg2(someValue);
        familyToOperation.setFamily(someValue);
        familyToOperation.setFamilyId(someValue);
        familyToOperation.setFamilyLabelLg1(someValue);
        familyToOperation.setFamilyLabelLg2(someValue);
        familyToOperation.setFamilyAltLabelLg1(someValue);
        familyToOperation.setFamilyAltLabelLg2(someValue);
        return familyToOperation;
    }

    @Test
    public void givenGetListeFamilyToOperation_whenListContainsOneFamilyToOperation() {
        opList.add(this.getAFamilyToOperation("1"));
        familyMap = operationsApiService.getListeFamilyToOperation(opList);
        Assertions.assertTrue(familyMap.containsKey("1"));
    }

    @Test
    public void givenGetListeFamilyToOperation_whenListContainsOneFamilyToOperationWitOperationId() {
        FamilyToOperation familyToOperation = this.getAFamilyToOperation("1");
        familyToOperation.setOperation("1");
        familyToOperation.setOperationId("1");
        familyToOperation.setOpLabelLg1("1");
        familyToOperation.setOpLabelLg2("1");
        familyToOperation.setSimsId("1");
        familyToOperation.setOpAltLabelLg1("1");
        familyToOperation.setOpAltLabelLg2("1");
        opList.add(familyToOperation);
        familyMap = operationsApiService.getListeFamilyToOperation(opList);
        Assertions.assertTrue(familyMap.containsKey("1"));
    }

    @Test
    public void givenGetListeFamilyToOperation_whenListContainsOneFamilyToOperationWitSims() {
        FamilyToOperation familyToOperation = this.getAFamilyToOperation("1");
        familyToOperation.setSimsId("1");
        opList.add(familyToOperation);
        familyMap = operationsApiService.getListeFamilyToOperation(opList);
        Assertions.assertTrue(familyMap.containsKey("1"));
    }

    @Test
    public void givenGetListeFamilyToOperation_whenListContainsOneFamilyToOperationWitIndicId() {
        FamilyToOperation familyToOperation = this.getAFamilyToOperation("1");
        familyToOperation.setIndic("1");
        familyToOperation.setIndicId("1");
        familyToOperation.setIndicLabelLg1("1");
        familyToOperation.setIndicLabelLg2("1");
        familyToOperation.setSimsId("1");
        familyToOperation.setIndicAltLabelLg1("1");
        familyToOperation.setIndicAltLabelLg2("1");
        opList.add(familyToOperation);
        familyMap = operationsApiService.getListeFamilyToOperation(opList);
        Assertions.assertTrue(familyMap.containsKey("1"));
    }

}

@@ -291,16 +291,41 @@
 tMocks;%0A
+import org.mockito.Mock;%0A
 import o
@@ -367,16 +367,16 @@
 ension;%0A
-
 %0Aimport 
@@ -517,16 +517,54 @@
 eration;
+%0Aimport fr.insee.rmes.utils.FileUtils;
 %0A%0A@Exten
@@ -675,16 +675,16 @@
 ctMocks%0A
-
     priv
@@ -731,16 +731,66 @@
 rvice;%0A%0A
+    @Mock%0A    protected FileUtils mockFileUtils;%0A%0A
     priv
@@ -4024,10 +4024,431 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void givenRemoveExclusions_whenFileIsEmpty() %7B%0A        // FamilyToOperation familyToOperation = this.getAFamilyToOperation(%221%22);%0A        // opList.add(familyToOperation);%0A        opList.add(this.getAFamilyToOperation(%221%22));%0A        opList.add(this.getAFamilyToOperation(%222%22));%0A        opList = operationsApiService.removeExclusions(opList);%0A        Assertions.assertEquals(2, opList.size());%0A%0A    %7D%0A%0A
 %7D%0A

add some tests