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("RolePermission")
class RolePermissionTest {

    private static Role newRole() {
        Role r = new Role();
        r.setId(UUID.randomUUID());
        r.setCode("ADMIN");
        r.setLibelle("Admin");
        r.setNiveauHierarchique(1);
        r.setTypeRole("SYSTEME");
        return r;
    }

    private static Permission newPermission() {
        Permission p = new Permission();
        p.setId(UUID.randomUUID());
        p.setCode("X > Y > Z");
        p.setModule("X");
        p.setRessource("Y");
        p.setAction("Z");
        return p;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        RolePermission rp = new RolePermission();
        rp.setRole(newRole());
        rp.setPermission(newPermission());
        rp.setCommentaire("Association");

        assertThat(rp.getRole()).isNotNull();
        assertThat(rp.getPermission()).isNotNull();
        assertThat(rp.getCommentaire()).isEqualTo("Association");
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        Role role = newRole();
        Permission perm = newPermission();
        RolePermission a = new RolePermission();
        a.setId(id);
        a.setRole(role);
        a.setPermission(perm);
        RolePermission b = new RolePermission();
        b.setId(id);
        b.setRole(role);
        b.setPermission(perm);
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        RolePermission rp = new RolePermission();
        rp.setRole(newRole());
        rp.setPermission(newPermission());
        assertThat(rp.toString()).isNotNull().isNotEmpty();
    }
}
