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

import dev.lions.unionflow.server.api.enums.vote.ModeScrutin;
import dev.lions.unionflow.server.api.enums.vote.StatutVote;
import dev.lions.unionflow.server.api.enums.vote.TypeVote;
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.LocalDateTime;
import java.util.UUID;

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

@DisplayName("Candidat")
class CandidatTest {

    private static CampagneVote newCampagneVote() {
        Organisation o = new Organisation();
        o.setId(UUID.randomUUID());
        o.setNom("Org");
        o.setTypeOrganisation("X");
        o.setStatut("ACTIVE");
        o.setEmail("org@test.com");
        CampagneVote c = new CampagneVote();
        c.setId(UUID.randomUUID());
        c.setTitre("Campagne");
        c.setOrganisation(o);
        c.setTypeVote(TypeVote.ELECTION_BUREAU);
        c.setModeScrutin(ModeScrutin.MAJORITAIRE_UN_TOUR);
        c.setStatut(StatutVote.OUVERT);
        c.setDateOuverture(LocalDateTime.now());
        c.setDateFermeture(LocalDateTime.now().plusDays(1));
        return c;
    }

    @Test
    @DisplayName("getters/setters")
    void gettersSetters() {
        Candidat cand = new Candidat();
        cand.setCampagneVote(newCampagneVote());
        cand.setNomCandidatureOuChoix("Jean Dupont");
        cand.setProfessionDeFoi("Profession de foi");
        cand.setNombreDeVoix(10);
        cand.setPourcentageObtenu(new BigDecimal("25.50"));

        assertThat(cand.getNomCandidatureOuChoix()).isEqualTo("Jean Dupont");
        assertThat(cand.getNombreDeVoix()).isEqualTo(10);
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        CampagneVote camp = newCampagneVote();
        Candidat a = new Candidat();
        a.setId(id);
        a.setCampagneVote(camp);
        a.setNomCandidatureOuChoix("C1");
        Candidat b = new Candidat();
        b.setId(id);
        b.setCampagneVote(camp);
        b.setNomCandidatureOuChoix("C1");
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        Candidat cand = new Candidat();
        cand.setCampagneVote(newCampagneVote());
        cand.setNomCandidatureOuChoix("X");
        assertThat(cand.toString()).isNotNull().isNotEmpty();
    }
}
