package dev.lions.unionflow.server.entity.mutuelle.epargne;

import dev.lions.unionflow.server.api.enums.mutuelle.epargne.TypeTransactionEpargne;
import dev.lions.unionflow.server.api.enums.wave.StatutTransactionWave;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

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

@DisplayName("TransactionEpargne")
class TransactionEpargneTest {

    private static CompteEpargne newCompte() {
        dev.lions.unionflow.server.entity.Membre m = new dev.lions.unionflow.server.entity.Membre();
        m.setId(UUID.randomUUID());
        m.setNumeroMembre("M1");
        m.setPrenom("A");
        m.setNom("B");
        m.setEmail("a@test.com");
        m.setDateNaissance(java.time.LocalDate.now());
        dev.lions.unionflow.server.entity.Organisation o = new dev.lions.unionflow.server.entity.Organisation();
        o.setId(UUID.randomUUID());
        o.setNom("O");
        o.setTypeOrganisation("X");
        o.setStatut("ACTIVE");
        o.setEmail("o@test.com");
        CompteEpargne c = new CompteEpargne();
        c.setId(UUID.randomUUID());
        c.setMembre(m);
        c.setOrganisation(o);
        c.setNumeroCompte("CE-1");
        c.setTypeCompte(dev.lions.unionflow.server.api.enums.mutuelle.epargne.TypeCompteEpargne.EPARGNE_LIBRE);
        c.setSoldeActuel(BigDecimal.ZERO);
        c.setSoldeBloque(BigDecimal.ZERO);
        c.setStatut(dev.lions.unionflow.server.api.enums.mutuelle.epargne.StatutCompteEpargne.ACTIF);
        c.setDateOuverture(java.time.LocalDate.now());
        return c;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        TransactionEpargne t = new TransactionEpargne();
        t.setCompte(newCompte());
        t.setType(TypeTransactionEpargne.DEPOT);
        t.setMontant(new BigDecimal("50000"));
        t.setDateTransaction(LocalDateTime.now());
        t.setStatutExecution(StatutTransactionWave.REUSSIE);

        assertThat(t.getType()).isEqualTo(TypeTransactionEpargne.DEPOT);
        assertThat(t.getMontant()).isEqualByComparingTo("50000");
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        CompteEpargne compte = newCompte();
        LocalDateTime dt = LocalDateTime.now();
        TransactionEpargne a = new TransactionEpargne();
        a.setId(id);
        a.setCompte(compte);
        a.setType(TypeTransactionEpargne.DEPOT);
        a.setMontant(BigDecimal.ONE);
        a.setDateTransaction(dt);
        TransactionEpargne b = new TransactionEpargne();
        b.setId(id);
        b.setCompte(compte);
        b.setType(TypeTransactionEpargne.DEPOT);
        b.setMontant(BigDecimal.ONE);
        b.setDateTransaction(dt);
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        TransactionEpargne t = new TransactionEpargne();
        t.setCompte(newCompte());
        t.setType(TypeTransactionEpargne.DEPOT);
        t.setMontant(BigDecimal.ONE);
        t.setDateTransaction(LocalDateTime.now());
        assertThat(t.toString()).isNotNull().isNotEmpty();
    }
}
