import pytest
from etl.epc.Record import EPCRecord
from backend.Property import Property
from recommendations.LightingRecommendations import LightingRecommendations

from recommendations.tests.test_data.materials import materials


class TestLightingRecommendations:

    def test_init_invalid_materials(self):
        epc_record = EPCRecord()
        epc_record.county = "Greater London Authority"
        input_property0 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property0.lighting = {"low_energy_proportion": 0}
        input_property0.already_installed = []
        # Test for invalid materials
        with pytest.raises(ValueError):
            LightingRecommendations(input_property0, [])

    def test_recommend_no_action_needed(self):
        # Case where no recommendation is needed
        epc_record = EPCRecord()
        epc_record.county = "Greater London Authority"
        input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property1.lighting = {"low_energy_proportion": 100}
        input_property1.already_installed = []

        lr = LightingRecommendations(input_property1, materials)
        lr.recommend()
        assert lr.recommendation == []

    def test_recommend_action_needed(self):
        # Case where recommendation is needed
        epc_record = EPCRecord()
        epc_record.county = "Greater London Authority"
        input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property1.lighting = {"low_energy_proportion": 0.80}
        input_property1.number_lighting_outlets = 20
        input_property1.already_installed = []

        lr = LightingRecommendations(input_property1, materials)
        lr.recommend()
        assert len(lr.recommendation) == 1

        # Note - this test may be dependent on the ofgem price caps
        assert lr.recommendation[0]["description_simulation"] == {'lighting-energy-eff': 'Very Good',
                                                                  'lighting-description': 'Low energy lighting in all '
                                                                                          'fixed outlets',
                                                                  'low-energy-lighting': 100}
        assert lr.recommendation[0]["description"] == 'Install low energy lighting in 4 outlets'
        assert lr.recommendation[0]["total"] == 14
