import pytest
from etl.epc_clean.epc_attributes.HotWaterAttributes import HotWaterAttributes
from etl.epc_clean.tests.test_data.test_hot_water_attributes_cases import hotwater_cases


class TestHotWaterAttributes:

    def test_init(self):
        # Test initialization with a valid description
        valid_description = 'Electric heat pump for water heating only, no cylinder thermostat'
        attr = HotWaterAttributes(valid_description)
        assert attr.description == 'electric heat pump for water heating only, no cylinder thermostat'

        # Test initialization with a description that contains none of the keywords
        with pytest.raises(ValueError):
            HotWaterAttributes('description without keywords')

    def test_empty_str_input(self):
        assert HotWaterAttributes("").process() == {
            'heater_type': None, 'system_type': None, 'thermostat_characteristics': None, 'heating_scope': None,
            'energy_recovery': None, 'tariff_type': None, 'extra_features': None, 'chp_systems': None,
            'distribution_system': None, 'no_system_present': None, 'assumed': None, 'appliance': None
        }

    @pytest.mark.parametrize(
        "test_case",
        hotwater_cases
    )
    def test_process_mainheat(self, test_case):
        expected_result = test_case.copy()
        del expected_result["original_description"]
        result = HotWaterAttributes(test_case['original_description']).process()
        assert sorted(result.items()) == sorted(expected_result.items())

    def test_invalid_description(self):
        # Test that invalid descriptions raise a ValueError
        invalid_descriptions = [
            "invalid description",
            "description with no known hotwater data_types",
        ]

        for description in invalid_descriptions:
            with pytest.raises(ValueError):
                HotWaterAttributes(description).process()

    def test_empty_description(self):
        processed = HotWaterAttributes("").process()
        for _, x in processed.items():
            assert x is None
