package dev.lions.unionflow.server.api.enums.audit;

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

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

@DisplayName("Tests pour PorteeAudit")
class PorteeAuditTest {

  @Test
  @DisplayName("Test de base - enum peut être utilisé")
  void testEnumUtilisable() {
    assertThat(PorteeAudit.ORGANISATION).isNotNull();
    assertThat(PorteeAudit.PLATEFORME).isNotNull();
  }

  @Nested
  @DisplayName("Tests des valeurs enum")
  class TestsValeursEnum {

    @Test
    @DisplayName("Test toutes les valeurs enum")
    void testToutesValeurs() {
      PorteeAudit[] values = PorteeAudit.values();
      assertThat(values).hasSize(2);
      assertThat(values).containsExactly(
          PorteeAudit.ORGANISATION,
          PorteeAudit.PLATEFORME);
    }

    @Test
    @DisplayName("Test valueOf - toutes les constantes")
    void testValueOf() {
      assertThat(PorteeAudit.valueOf("ORGANISATION")).isEqualTo(PorteeAudit.ORGANISATION);
      assertThat(PorteeAudit.valueOf("PLATEFORME")).isEqualTo(PorteeAudit.PLATEFORME);

      assertThatThrownBy(() -> PorteeAudit.valueOf("INEXISTANT"))
          .isInstanceOf(IllegalArgumentException.class);
    }

    @ParameterizedTest
    @EnumSource(PorteeAudit.class)
    @DisplayName("Test getLibelle pour toutes les valeurs")
    void testGetLibelle(PorteeAudit portee) {
      assertThat(portee.getLibelle()).isNotNull().isNotEmpty();
    }

    @Test
    @DisplayName("Test getLibelle contient libellé attendu")
    void testGetLibelleContenu() {
      assertThat(PorteeAudit.ORGANISATION.getLibelle()).contains("organisation");
      assertThat(PorteeAudit.PLATEFORME.getLibelle()).contains("Super Admin");
    }

    @Test
    @DisplayName("Test name()")
    void testName() {
      assertThat(PorteeAudit.ORGANISATION.name()).isEqualTo("ORGANISATION");
      assertThat(PorteeAudit.PLATEFORME.name()).isEqualTo("PLATEFORME");
    }
  }
}
