"""
init-mater-project

Copyright (C) 2025 [Lauranne Sarribouette] <lauranne.sarribouette@univ-grenoble-alpes.fr>

SPDX-License-Identifier: LGPL-3.0-or-later
"""

from src.init_mater_project.src.lib.validation import (
    validate_mapping_completeness,
    count_mapping_statistics,
    validate_local_dimensions,
    validate_mater_ready_data,
)


class TestValidateMappingCompleteness:
    """Test validate_mapping_completeness function"""

    def test_complete_mapping_validation(self, complete_mapping):
        """Test validation of complete mapping without TODOs"""
        result = validate_mapping_completeness(complete_mapping)

        assert result["total"] == 2
        assert result["mapped"] == 2
        assert result["todo"] == 0
        assert result["completion_rate"] == 100.0
        assert result["can_proceed"] is True
        assert len(result["todo_entries"]) == 0

    def test_incomplete_mapping_validation(self, incomplete_mapping):
        """Test validation of incomplete mapping with TODOs"""
        result = validate_mapping_completeness(incomplete_mapping)

        assert result["total"] == 2
        assert result["mapped"] == 1
        assert result["todo"] == 1
        assert result["completion_rate"] == 50.0
        assert result["can_proceed"] is False
        assert len(result["todo_entries"]) == 1

    def test_empty_mapping_validation(self):
        """Test validation of empty mapping"""
        result = validate_mapping_completeness([])

        assert result["total"] == 0
        assert result["mapped"] == 0
        assert result["todo"] == 0
        assert result["completion_rate"] == 0.0
        assert result["can_proceed"] is True


class TestCountMappingStatistics:
    """Test count_mapping_statistics function"""

    def test_count_complete_mapping(self, complete_mapping):
        """Test counting statistics for complete mapping"""
        mapped, todo = count_mapping_statistics(complete_mapping)

        assert mapped == 2
        assert todo == 0

    def test_count_incomplete_mapping(self, incomplete_mapping):
        """Test counting statistics for incomplete mapping"""
        mapped, todo = count_mapping_statistics(incomplete_mapping)

        assert mapped == 1
        assert todo == 1

    def test_count_empty_mapping(self):
        """Test counting statistics for empty mapping"""
        mapped, todo = count_mapping_statistics([])

        assert mapped == 0
        assert todo == 0


class TestValidateMaterReadyData:
    """Test validate_mater_ready_data function"""

    def test_valid_data_with_derived_dimensions(self, valid_derived_dimension_data):
        """Test validation of valid data including derived dimension names"""
        result = validate_mater_ready_data(valid_derived_dimension_data)
        assert result is True

    def test_invalid_dimension_name_rejected(self, invalid_dimension_name_data):
        """Test validation rejection of invalid dimension name"""
        result = validate_mater_ready_data(invalid_dimension_name_data)
        assert result is False


class TestValidateLocalDimensions:
    """Test validate_local_dimensions function"""

    def test_valid_dimensions_including_root(self, valid_local_dimensions):
        """Test validation of valid dimensions including root"""
        result = validate_local_dimensions(valid_local_dimensions)
        assert result is True

    def test_invalid_dimension_name_rejected(self, invalid_local_dimensions):
        """Test validation rejection of invalid dimension name"""
        result = validate_local_dimensions(invalid_local_dimensions)
        assert result is False
