package de.gecheckt.pdf.umbenenner.domain.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

/**
 * Tests for PdfPageCount record.
 * <p>
 * Focus: Validate constructor constraints, method behavior, and edge cases.
 */
class PdfPageCountTest {

    @Test
    void testConstructor_ValidValue_CreatesInstance() {
        // Arrange
        int validPageCount = 1;

        // Act
        PdfPageCount pageCount = new PdfPageCount(validPageCount);

        // Assert
        assertEquals(validPageCount, pageCount.value());
    }

    @Test
    void testConstructor_ZeroValue_ThrowsException() {
        // Arrange
        int invalidPageCount = 0;

        // Act & Assert
        IllegalArgumentException exception = assertThrows(
            IllegalArgumentException.class,
            () -> new PdfPageCount(invalidPageCount)
        );
        
        assertTrue(exception.getMessage().contains("Page count must be >= 1"));
    }

    @Test
    void testConstructor_NegativeValue_ThrowsException() {
        // Arrange
        int invalidPageCount = -1;

        // Act & Assert
        IllegalArgumentException exception = assertThrows(
            IllegalArgumentException.class,
            () -> new PdfPageCount(invalidPageCount)
        );
        
        assertTrue(exception.getMessage().contains("Page count must be >= 1"));
    }

    @Test
    void testExceedsLimit_ValueBelowLimit_ReturnsFalse() {
        // Arrange
        PdfPageCount pageCount = new PdfPageCount(5);
        int limit = 10;

        // Act
        boolean result = pageCount.exceedsLimit(limit);

        // Assert
        assertFalse(result);
    }

    @Test
    void testExceedsLimit_ValueAtLimit_ReturnsFalse() {
        // Arrange
        PdfPageCount pageCount = new PdfPageCount(5);
        int limit = 5;

        // Act
        boolean result = pageCount.exceedsLimit(limit);

        // Assert
        assertFalse(result);
    }

    @Test
    void testExceedsLimit_ValueAboveLimit_ReturnsTrue() {
        // Arrange
        PdfPageCount pageCount = new PdfPageCount(10);
        int limit = 5;

        // Act
        boolean result = pageCount.exceedsLimit(limit);

        // Assert
        assertTrue(result);
    }

    @Test
    void testExceedsLimit_NegativeLimit_HandlesCorrectly() {
        // Arrange
        PdfPageCount pageCount = new PdfPageCount(5);
        int limit = -1;

        // Act
        boolean result = pageCount.exceedsLimit(limit);

        // Assert
        assertTrue(result); // Any positive page count exceeds a negative limit
    }

    @Test
    void testEquals_SameValue_ObjectsEqual() {
        // Arrange
        PdfPageCount first = new PdfPageCount(5);
        PdfPageCount second = new PdfPageCount(5);

        // Assert
        assertEquals(first, second);
        assertEquals(first.hashCode(), second.hashCode());
    }

    @Test
    void testEquals_DifferentValue_ObjectsNotEqual() {
        // Arrange
        PdfPageCount first = new PdfPageCount(5);
        PdfPageCount second = new PdfPageCount(6);

        // Assert
        assertNotEquals(first, second);
        assertNotEquals(first.hashCode(), second.hashCode());
    }

    @Test
    void testToString_ReturnsExpectedFormat() {
        // Arrange
        PdfPageCount pageCount = new PdfPageCount(42);

        // Act
        String result = pageCount.toString();

        // Assert
        assertTrue(result.contains("PdfPageCount"));
        assertTrue(result.contains("value=42"));
    }
}