import pytest
from etl.epc_clean.epc_attributes.MainFuelAttributes import MainFuelAttributes
from etl.epc_clean.tests.test_data.test_main_fuel_attributes_cases import mainfuel_cases


class TestMainHeatControlAttributes:

    def test_init(self):
        # Test initialization with a valid description
        valid_description = 'mains gas (not community)'
        attr = MainFuelAttributes(valid_description)
        assert attr.description == 'mains gas not community'

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

    def test_empty_str(self):
        assert MainFuelAttributes("").process() == {
            'fuel_type': 'unknown', 'tariff_type': None, 'is_community': False,
            'no_individual_heating_or_community_network': False, 'complex_fuel_type': None
        }

    @pytest.mark.parametrize(
        "test_case",
        mainfuel_cases
    )
    def test_process_mainheat(self, test_case):
        expected_result = test_case.copy()
        del expected_result["original_description"]
        result = MainFuelAttributes(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 fuel data_types",
        ]

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