package dev.lions.unionflow.server.entity;

import dev.lions.unionflow.server.api.enums.solidarite.TypeWorkflow;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.UUID;

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

@DisplayName("WorkflowValidationConfig")
class WorkflowValidationConfigTest {

    private static Organisation newOrganisation() {
        Organisation o = new Organisation();
        o.setId(UUID.randomUUID());
        o.setNom("Org");
        o.setTypeOrganisation("X");
        o.setStatut("ACTIVE");
        o.setEmail("org@test.com");
        return o;
    }

    private static Role newRole() {
        Role r = new Role();
        r.setId(UUID.randomUUID());
        r.setCode("SECRETAIRE");
        r.setLibelle("Secrétaire");
        r.setNiveauHierarchique(1);
        r.setTypeRole("ORGANISATION");
        return r;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        WorkflowValidationConfig w = new WorkflowValidationConfig();
        w.setOrganisation(newOrganisation());
        w.setTypeWorkflow(TypeWorkflow.DEMANDE_AIDE);
        w.setEtapeNumero(1);
        w.setRoleRequis(newRole());
        w.setLibelleEtape("Étape 1 - Secrétaire");
        w.setDelaiMaxHeures(72);

        assertThat(w.getTypeWorkflow()).isEqualTo(TypeWorkflow.DEMANDE_AIDE);
        assertThat(w.getEtapeNumero()).isEqualTo(1);
        assertThat(w.getLibelleEtape()).isEqualTo("Étape 1 - Secrétaire");
        assertThat(w.getDelaiMaxHeures()).isEqualTo(72);
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        Organisation o = newOrganisation();
        WorkflowValidationConfig a = new WorkflowValidationConfig();
        a.setId(id);
        a.setOrganisation(o);
        a.setTypeWorkflow(TypeWorkflow.DEMANDE_AIDE);
        a.setEtapeNumero(1);
        a.setLibelleEtape("E1");
        WorkflowValidationConfig b = new WorkflowValidationConfig();
        b.setId(id);
        b.setOrganisation(o);
        b.setTypeWorkflow(TypeWorkflow.DEMANDE_AIDE);
        b.setEtapeNumero(1);
        b.setLibelleEtape("E1");
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        WorkflowValidationConfig w = new WorkflowValidationConfig();
        w.setOrganisation(newOrganisation());
        w.setTypeWorkflow(TypeWorkflow.DEMANDE_AIDE);
        w.setEtapeNumero(1);
        w.setLibelleEtape("E1");
        assertThat(w.toString()).isNotNull().isNotEmpty();
    }
}
