package dev.lions.unionflow.server.entity;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

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

@DisplayName("ModuleOrganisationActif")
class ModuleOrganisationActifTest {

    private static Organisation newOrganisation() {
        Organisation o = new Organisation();
        o.setId(UUID.randomUUID());
        return o;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        ModuleOrganisationActif m = new ModuleOrganisationActif();
        m.setOrganisation(newOrganisation());
        m.setModuleCode("CREDIT_EPARGNE");
        m.setDateActivation(LocalDateTime.now());
        m.setParametres("{\"taux_max\":18}");

        assertThat(m.getModuleCode()).isEqualTo("CREDIT_EPARGNE");
        assertThat(m.getDateActivation()).isNotNull();
        assertThat(m.getParametres()).contains("taux_max");
    }

    @Test
    @DisplayName("dateActivation par défaut")
    void dateActivationDefaut() {
        ModuleOrganisationActif m = new ModuleOrganisationActif();
        m.setOrganisation(newOrganisation());
        m.setModuleCode("X");
        assertThat(m.getDateActivation()).isNotNull();
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        Organisation o = newOrganisation();
        LocalDateTime sameDate = LocalDateTime.of(2026, 1, 15, 10, 0);
        ModuleOrganisationActif a = new ModuleOrganisationActif();
        a.setId(id);
        a.setOrganisation(o);
        a.setModuleCode("M1");
        a.setDateActivation(sameDate);
        ModuleOrganisationActif b = new ModuleOrganisationActif();
        b.setId(id);
        b.setOrganisation(o);
        b.setModuleCode("M1");
        b.setDateActivation(sameDate);
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        ModuleOrganisationActif m = new ModuleOrganisationActif();
        m.setOrganisation(newOrganisation());
        m.setModuleCode("X");
        assertThat(m.toString()).isNotNull().isNotEmpty();
    }
}
