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("PieceJointe")
class PieceJointeTest {

    private static Document newDocument() {
        Document d = new Document();
        d.setId(UUID.randomUUID());
        d.setNomFichier("f.pdf");
        d.setCheminStockage("/f.pdf");
        d.setTailleOctets(100L);
        return d;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        PieceJointe pj = new PieceJointe();
        pj.setOrdre(1);
        pj.setLibelle("Pièce 1");
        pj.setCommentaire("Comment");
        pj.setDocument(newDocument());
        pj.setTypeEntiteRattachee("MEMBRE");
        pj.setEntiteRattacheeId(UUID.randomUUID());

        assertThat(pj.getOrdre()).isEqualTo(1);
        assertThat(pj.getLibelle()).isEqualTo("Pièce 1");
        assertThat(pj.getTypeEntiteRattachee()).isEqualTo("MEMBRE");
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        UUID entiteId = UUID.randomUUID();
        Document d = newDocument();
        PieceJointe a = new PieceJointe();
        a.setId(id);
        a.setOrdre(1);
        a.setDocument(d);
        a.setTypeEntiteRattachee("MEMBRE");
        a.setEntiteRattacheeId(entiteId);
        PieceJointe b = new PieceJointe();
        b.setId(id);
        b.setOrdre(1);
        b.setDocument(d);
        b.setTypeEntiteRattachee("MEMBRE");
        b.setEntiteRattacheeId(entiteId);
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        PieceJointe pj = new PieceJointe();
        pj.setOrdre(1);
        pj.setDocument(newDocument());
        pj.setTypeEntiteRattachee("MEMBRE");
        pj.setEntiteRattacheeId(UUID.randomUUID());
        assertThat(pj.toString()).isNotNull().isNotEmpty();
    }
}
