//Validator JUnits tests

package org.example.petshopdesktop;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ValidatorTest {

    //isPresent
    @Test
    void isPresent_nullValue_returnsError() {
        String result = Validator.isPresent(null, "Name");
        assertFalse(result.isEmpty(), "null value should produce an error message");
    }

    @Test
    void isPresent_blankValue_returnsError() {
        assertFalse(Validator.isPresent("   ", "Name").isEmpty());
    }

    @Test
    void isPresent_emptyString_returnsError() {
        assertFalse(Validator.isPresent("", "Name").isEmpty());
    }

    @Test
    void isPresent_validValue_returnsEmpty() {
        assertTrue(Validator.isPresent("Leon", "Name").isEmpty());
    }

    //isNonNegativeDouble
    @Test
    void isNonNegativeDouble_positiveValue_returnsEmpty() {
        assertTrue(Validator.isNonNegativeDouble("5.5", "Price").isEmpty());
    }

    @Test
    void isNonNegativeDouble_zero_returnsEmpty() {
        assertTrue(Validator.isNonNegativeDouble("0", "Price").isEmpty());
    }

    @Test
    void isNonNegativeDouble_negativeValue_returnsError() {
        assertFalse(Validator.isNonNegativeDouble("-1.0", "Price").isEmpty());
    }

    @Test
    void isNonNegativeDouble_nonNumeric_returnsError() {
        assertFalse(Validator.isNonNegativeDouble("abc", "Price").isEmpty());
    }

    @Test
    void isNonNegativeDouble_nullInput_returnsError() {
        assertFalse(Validator.isNonNegativeDouble(null, "Price").isEmpty());
    }

    //isDoubleInRange
    @Test
    void isDoubleInRange_withinRange_returnsEmpty() {
        assertTrue(Validator.isDoubleInRange("5.0", "Discount", 0.0, 10.0).isEmpty());
    }

    @Test
    void isDoubleInRange_atMinBoundary_returnsEmpty() {
        assertTrue(Validator.isDoubleInRange("0.0", "Discount", 0.0, 10.0).isEmpty());
    }

    @Test
    void isDoubleInRange_atMaxBoundary_returnsEmpty() {
        assertTrue(Validator.isDoubleInRange("10.0", "Discount", 0.0, 10.0).isEmpty());
    }

    @Test
    void isDoubleInRange_belowMin_returnsError() {
        assertFalse(Validator.isDoubleInRange("-1.0", "Discount", 0.0, 10.0).isEmpty());
    }

    @Test
    void isDoubleInRange_aboveMax_returnsError() {
        assertFalse(Validator.isDoubleInRange("11.0", "Discount", 0.0, 10.0).isEmpty());
    }

    @Test
    void isDoubleInRange_nonNumeric_returnsError() {
        assertFalse(Validator.isDoubleInRange("abc", "Discount", 0.0, 10.0).isEmpty());
    }

    @Test
    void isDoubleInRange_nullInput_returnsError() {
        assertFalse(Validator.isDoubleInRange(null, "Discount", 0.0, 10.0).isEmpty());
    }

    //isNonNegativeInteger
    @Test
    void isNonNegativeInteger_positiveValue_returnsEmpty() {
        assertTrue(Validator.isNonNegativeInteger("10", "Quantity").isEmpty());
    }

    @Test
    void isNonNegativeInteger_zero_returnsEmpty() {
        assertTrue(Validator.isNonNegativeInteger("0", "Quantity").isEmpty());
    }

    @Test
    void isNonNegativeInteger_negativeValue_returnsError() {
        assertFalse(Validator.isNonNegativeInteger("-1", "Quantity").isEmpty());
    }

    @Test
    void isNonNegativeInteger_decimal_returnsError() {
        assertFalse(Validator.isNonNegativeInteger("1.5", "Quantity").isEmpty());
    }

    @Test
    void isNonNegativeInteger_nonNumeric_returnsError() {
        assertFalse(Validator.isNonNegativeInteger("abc", "Quantity").isEmpty());
    }

    @Test
    void isNonNegativeInteger_nullInput_returnsError() {
        assertFalse(Validator.isNonNegativeInteger(null, "Quantity").isEmpty());
    }

    //isLessThanVarChars
    @Test
    void isLessThanVarChars_withinLimit_returnsEmpty() {
        assertTrue(Validator.isLessThanVarChars("Hello", "Name", 10).isEmpty());
    }

    @Test
    void isLessThanVarChars_exactlyAtLimit_returnsEmpty() {
        assertTrue(Validator.isLessThanVarChars("Hello", "Name", 5).isEmpty());
    }

    @Test
    void isLessThanVarChars_exceedsLimit_returnsError() {
        assertFalse(Validator.isLessThanVarChars("Hello World", "Name", 5).isEmpty());
    }

    @Test
    void isLessThanVarChars_nullInput_returnsError() {
        assertFalse(Validator.isLessThanVarChars(null, "Name", 10).isEmpty());
    }

    @Test
    void isLessThanVarChars_emptyString_returnsEmpty() {
        assertTrue(Validator.isLessThanVarChars("", "Name", 5).isEmpty());
    }

    //isValidEmail
    @Test
    void isValidEmail_validEmail_returnsEmpty() {
        assertTrue(Validator.isValidEmail("user@example.com", "Email").isEmpty());
    }

    @Test
    void isValidEmail_missingAtSign_returnsError() {
        assertFalse(Validator.isValidEmail("userexample.com", "Email").isEmpty());
    }

    @Test
    void isValidEmail_missingDomain_returnsError() {
        assertFalse(Validator.isValidEmail("user@", "Email").isEmpty());
    }

    @Test
    void isValidEmail_shortTld_returnsError() {
        assertFalse(Validator.isValidEmail("user@example.c", "Email").isEmpty());
    }

    @Test
    void isValidEmail_nullInput_returnsError() {
        assertFalse(Validator.isValidEmail(null, "Email").isEmpty());
    }

    @Test
    void isValidEmail_emptyString_returnsError() {
        assertFalse(Validator.isValidEmail("", "Email").isEmpty());
    }

    //isValidPhoneNumber
    @Test
    void isValidPhoneNumber_validFormat_returnsEmpty() {
        assertTrue(Validator.isValidPhoneNumber("403-555-1234", "Phone").isEmpty());
    }

    @Test
    void isValidPhoneNumber_missingDashes_returnsError() {
        assertFalse(Validator.isValidPhoneNumber("4035551234", "Phone").isEmpty());
    }

    @Test
    void isValidPhoneNumber_lettersPresent_returnsError() {
        assertFalse(Validator.isValidPhoneNumber("abc-def-ghij", "Phone").isEmpty());
    }

    @Test
    void isValidPhoneNumber_wrongSegmentLength_returnsError() {
        assertFalse(Validator.isValidPhoneNumber("40-5551-234", "Phone").isEmpty());
    }

    @Test
    void isValidPhoneNumber_nullInput_returnsError() {
        assertFalse(Validator.isValidPhoneNumber(null, "Phone").isEmpty());
    }

    @Test
    void isValidPhoneNumber_emptyString_returnsError() {
        assertFalse(Validator.isValidPhoneNumber("", "Phone").isEmpty());
    }
}
