package com.gnx.telemedicine.util;

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

/**
 * Unit tests for PasswordValidator utility class.
 */
class PasswordValidatorTest {

    @Test
    void testValidPassword() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("ValidPass123!");
        assertTrue(result.isValid(), "Password should be valid");
    }

    @Test
    void testPasswordTooShort() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("Short1!");
        assertFalse(result.isValid(), "Password should be invalid");
        assertTrue(result.getMessage().contains("at least"), "Error message should mention minimum length");
    }

    @Test
    void testPasswordMissingUppercase() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("lowercase123!");
        assertFalse(result.isValid(), "Password should be invalid");
        assertTrue(result.getMessage().contains("uppercase"), "Error message should mention uppercase");
    }

    @Test
    void testPasswordMissingLowercase() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("UPPERCASE123!");
        assertFalse(result.isValid(), "Password should be invalid");
        assertTrue(result.getMessage().contains("lowercase"), "Error message should mention lowercase");
    }

    @Test
    void testPasswordMissingDigit() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("NoDigitHere!");
        assertFalse(result.isValid(), "Password should be invalid");
        assertTrue(result.getMessage().contains("digit"), "Error message should mention digit");
    }

    @Test
    void testPasswordMissingSpecialChar() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("NoSpecialChar123");
        assertFalse(result.isValid(), "Password should be invalid");
        assertTrue(result.getMessage().contains("special"), "Error message should mention special character");
    }

    @Test
    void testPasswordNull() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic(null);
        assertFalse(result.isValid(), "Null password should be invalid");
        assertTrue(result.getMessage().contains("required"), "Error message should mention required");
    }

    @Test
    void testPasswordEmpty() {
        PasswordValidator.ValidationResult result = PasswordValidator.validateStatic("");
        assertFalse(result.isValid(), "Empty password should be invalid");
    }

    @Test
    void testPasswordStrengthCalculation() {
        PasswordValidator validator = new PasswordValidator();
        int weakScore = validator.calculateStrength("weak");
        int mediumScore = validator.calculateStrength("MediumPass123!");
        int strongScore = validator.calculateStrength("VeryStrongPassword123!@#");
        
        assertTrue(weakScore < mediumScore, "Weak password should have lower score");
        assertTrue(mediumScore < strongScore, "Strong password should have higher score");
        assertTrue(strongScore > 50, "Strong password should have score > 50");
    }
}

