package dev.lions.unionflow.server.entity.tontine;

import dev.lions.unionflow.server.api.enums.tontine.FrequenceTour;
import dev.lions.unionflow.server.api.enums.tontine.StatutTontine;
import dev.lions.unionflow.server.api.enums.tontine.TypeTontine;
import dev.lions.unionflow.server.entity.Organisation;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.UUID;

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

@DisplayName("Tontine")
class TontineTest {

    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;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        Tontine t = new Tontine();
        t.setNom("Tontine mensuelle");
        t.setDescription("Description");
        t.setOrganisation(newOrganisation());
        t.setTypeTontine(TypeTontine.ROTATIVE_CLASSIQUE);
        t.setFrequence(FrequenceTour.MENSUELLE);
        t.setStatut(StatutTontine.EN_COURS);
        t.setMontantMiseParTour(new BigDecimal("10000"));
        t.setLimiteParticipants(20);

        assertThat(t.getNom()).isEqualTo("Tontine mensuelle");
        assertThat(t.getTypeTontine()).isEqualTo(TypeTontine.ROTATIVE_CLASSIQUE);
        assertThat(t.getFrequence()).isEqualTo(FrequenceTour.MENSUELLE);
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        Organisation o = newOrganisation();
        Tontine a = new Tontine();
        a.setId(id);
        a.setNom("N");
        a.setOrganisation(o);
        a.setTypeTontine(TypeTontine.ROTATIVE_CLASSIQUE);
        a.setFrequence(FrequenceTour.MENSUELLE);
        a.setStatut(StatutTontine.PLANIFIEE);
        Tontine b = new Tontine();
        b.setId(id);
        b.setNom("N");
        b.setOrganisation(o);
        b.setTypeTontine(TypeTontine.ROTATIVE_CLASSIQUE);
        b.setFrequence(FrequenceTour.MENSUELLE);
        b.setStatut(StatutTontine.PLANIFIEE);
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        Tontine t = new Tontine();
        t.setNom("X");
        t.setOrganisation(newOrganisation());
        t.setTypeTontine(TypeTontine.ROTATIVE_CLASSIQUE);
        t.setFrequence(FrequenceTour.MENSUELLE);
        t.setStatut(StatutTontine.PLANIFIEE);
        assertThat(t.toString()).isNotNull().isNotEmpty();
    }
}
