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

import dev.lions.unionflow.server.api.enums.agricole.StatutCampagneAgricole;
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.util.UUID;

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

@DisplayName("CampagneAgricole")
class CampagneAgricoleTest {

    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() {
        CampagneAgricole c = new CampagneAgricole();
        c.setOrganisation(newOrganisation());
        c.setDesignation("Campagne maïs 2025");
        c.setTypeCulturePrincipale("Maïs");
        c.setSurfaceTotaleEstimeeHectares(new BigDecimal("10.5"));
        c.setVolumePrevisionnelTonnes(new BigDecimal("50"));
        c.setVolumeReelTonnes(new BigDecimal("48"));
        c.setStatut(StatutCampagneAgricole.RECOLTE);

        assertThat(c.getDesignation()).isEqualTo("Campagne maïs 2025");
        assertThat(c.getTypeCulturePrincipale()).isEqualTo("Maïs");
        assertThat(c.getStatut()).isEqualTo(StatutCampagneAgricole.RECOLTE);
    }

    @Test
    @DisplayName("equals et hashCode")
    void equalsHashCode() {
        UUID id = UUID.randomUUID();
        Organisation o = newOrganisation();
        CampagneAgricole a = new CampagneAgricole();
        a.setId(id);
        a.setOrganisation(o);
        a.setDesignation("D");
        a.setStatut(StatutCampagneAgricole.PREPARATION);
        CampagneAgricole b = new CampagneAgricole();
        b.setId(id);
        b.setOrganisation(o);
        b.setDesignation("D");
        b.setStatut(StatutCampagneAgricole.PREPARATION);
        assertThat(a).isEqualTo(b);
        assertThat(a.hashCode()).isEqualTo(b.hashCode());
    }

    @Test
    @DisplayName("toString non null")
    void toString_nonNull() {
        CampagneAgricole c = new CampagneAgricole();
        c.setOrganisation(newOrganisation());
        c.setDesignation("X");
        c.setStatut(StatutCampagneAgricole.PREPARATION);
        assertThat(c.toString()).isNotNull().isNotEmpty();
    }
}
