package dev.lions.unionflow.server.api.dto.base;

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

import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

/**
 * Tests unitaires pour PageResponse.
 * Couvre constructeur, getters, hasNext (true/false), hasPrevious (true/false).
 *
 * @author UnionFlow Team
 * @version 1.0
 * @since 2026-02-21
 */
@DisplayName("Tests PageResponse")
class PageResponseTest {

  @Nested
  @DisplayName("Constructeur et getters")
  class ConstructeurEtGetters {

    @Test
    @DisplayName("constructeur initialise tous les champs")
    void testConstructeur() {
      List<String> contenu = List.of("a", "b");
      PageResponse<String> page = new PageResponse<>(contenu, 0, 10, 25L, 3);
      assertThat(page.getContenu()).isSameAs(contenu);
      assertThat(page.getPage()).isEqualTo(0);
      assertThat(page.getTaille()).isEqualTo(10);
      assertThat(page.getTotalElements()).isEqualTo(25L);
      assertThat(page.getTotalPages()).isEqualTo(3);
    }
  }

  @Nested
  @DisplayName("hasNext")
  class HasNext {

    @Test
    @DisplayName("hasNext retourne true quand page < totalPages - 1")
    void testHasNextTrue() {
      PageResponse<String> page = new PageResponse<>(List.of("a"), 0, 10, 25L, 3);
      assertThat(page.hasNext()).isTrue();
    }

    @Test
    @DisplayName("hasNext retourne false quand page == totalPages - 1")
    void testHasNextFalseDernierePage() {
      PageResponse<String> page = new PageResponse<>(List.of("a"), 2, 10, 25L, 3);
      assertThat(page.hasNext()).isFalse();
    }

    @Test
    @DisplayName("hasNext retourne false quand une seule page")
    void testHasNextFalseUneSeulePage() {
      PageResponse<String> page = new PageResponse<>(List.of("a", "b"), 0, 10, 2L, 1);
      assertThat(page.hasNext()).isFalse();
    }
  }

  @Nested
  @DisplayName("hasPrevious")
  class HasPrevious {

    @Test
    @DisplayName("hasPrevious retourne false sur la première page")
    void testHasPreviousFalse() {
      PageResponse<String> page = new PageResponse<>(List.of("a"), 0, 10, 25L, 3);
      assertThat(page.hasPrevious()).isFalse();
    }

    @Test
    @DisplayName("hasPrevious retourne true quand page > 0")
    void testHasPreviousTrue() {
      PageResponse<String> page = new PageResponse<>(List.of("a"), 1, 10, 25L, 3);
      assertThat(page.hasPrevious()).isTrue();
    }
  }
}
