package dev.lions.unionflow.server.entity;

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("Role")
class RoleTest {

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        Role r = new Role();
        r.setCode("ADMIN");
        r.setLibelle("Administrateur");
        r.setDescription("Rôle admin");
        r.setNiveauHierarchique(10);
        r.setTypeRole(Role.TypeRole.SYSTEME.name());

        assertThat(r.getCode()).isEqualTo("ADMIN");
        assertThat(r.getLibelle()).isEqualTo("Administrateur");
        assertThat(r.getNiveauHierarchique()).isEqualTo(10);
        assertThat(r.getTypeRole()).isEqualTo("SYSTEME");
    }

    @Test
    @DisplayName("isRoleSysteme")
    void isRoleSysteme() {
        Role r = new Role();
        r.setCode("X");
        r.setLibelle("X");
        r.setTypeRole(Role.TypeRole.SYSTEME.name());
        assertThat(r.isRoleSysteme()).isTrue();
        r.setTypeRole(Role.TypeRole.ORGANISATION.name());
        assertThat(r.isRoleSysteme()).isFalse();
    }

    @Test
    @DisplayName("TypeRole enum")
    void typeRoleEnum() {
        assertThat(Role.TypeRole.SYSTEME.name()).isEqualTo("SYSTEME");
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        Role a = new Role();
        a.setId(id);
        a.setCode("C1");
        a.setLibelle("L1");
        a.setNiveauHierarchique(1);
        a.setTypeRole("SYSTEME");
        Role b = new Role();
        b.setId(id);
        b.setCode("C1");
        b.setLibelle("L1");
        b.setNiveauHierarchique(1);
        b.setTypeRole("SYSTEME");
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        Role r = new Role();
        r.setCode("X");
        r.setLibelle("X");
        r.setNiveauHierarchique(100);
        r.setTypeRole("PERSONNALISE");
        assertThat(r.toString()).isNotNull().isNotEmpty();
    }
}
