from backend.Property import Property
from recommendations.VentilationRecommendations import VentilationRecommendations
from recommendations.tests.test_data.materials import materials
from etl.epc.Record import EPCRecord


class TestVentilationRecommendations:

    def test_natural_ventilation(self):
        epc_record = EPCRecord(mechanical_ventilation="natural")
        input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property1.already_installed = []

        recommender = VentilationRecommendations(
            property_instance=input_property1,
            materials=materials
        )

        assert not recommender.recommendation

        recommender.recommend(phase=None)

        assert len(recommender.recommendation) == 1

        assert recommender.recommendation[0]["total"] == 560.0
        assert recommender.recommendation[0]["type"] == "mechanical_ventilation"
        assert len(recommender.recommendation[0]["parts"]) == 1
        assert recommender.recommendation[0]["parts"][0][
                   "description"] == 'Decentralised mechanical extract ventilation'
        assert recommender.recommendation[0]["parts"][0]["quantity"] == 2

    def test_missing_ventilation(self):
        epc_record = EPCRecord(mechanical_ventilation=None)
        input_property2 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property2.already_installed = []

        recommender2 = VentilationRecommendations(
            property_instance=input_property2,
            materials=materials
        )

        assert not recommender2.recommendation

        recommender2.recommend(phase=None)

        assert len(recommender2.recommendation) == 1

        assert recommender2.recommendation[0]["total"] == 560.0
        assert recommender2.recommendation[0]["type"] == "mechanical_ventilation"
        assert len(recommender2.recommendation[0]["parts"]) == 1
        assert recommender2.recommendation[0]["parts"][0][
                   "description"] == 'Decentralised mechanical extract ventilation'
        assert recommender2.recommendation[0]["parts"][0]["quantity"] == 2

    def test_nodata_ventilation(self):
        epc_record = EPCRecord(mechanical_ventilation="NO DATA!!")
        input_property3 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property3.already_installed = []

        recommender3 = VentilationRecommendations(
            property_instance=input_property3,
            materials=materials
        )

        assert not recommender3.recommendation

        recommender3.recommend(phase=None)

        assert len(recommender3.recommendation) == 1

        assert recommender3.recommendation[0]["total"] == 560.0
        assert recommender3.recommendation[0]["type"] == "mechanical_ventilation"
        assert len(recommender3.recommendation[0]["parts"]) == 1
        assert recommender3.recommendation[0]["parts"][0][
                   "description"] == 'Decentralised mechanical extract ventilation'
        assert recommender3.recommendation[0]["parts"][0]["quantity"] == 2

    def test_existing_ventilation_1(self):
        epc_record = EPCRecord(mechanical_ventilation="mechanical, extract only")
        input_property4 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property4.already_installed = []
        input_property4.identify_ventilation()
        assert input_property4.has_ventilation

        recommender4 = VentilationRecommendations(
            property_instance=input_property4,
            materials=materials
        )

        assert not recommender4.recommendation

        recommender4.recommend(phase=None)

        assert not recommender4.recommendation

    def test_existing_ventilation_2(self):
        epc_record = EPCRecord(mechanical_ventilation="mechanical, supply and extract")
        input_property5 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
        input_property5.already_installed = []
        input_property5.identify_ventilation()
        assert input_property5.has_ventilation

        recommender5 = VentilationRecommendations(
            property_instance=input_property5,
            materials=materials
        )

        assert not recommender5.recommendation

        recommender5.recommend(phase=None)

        assert not recommender5.recommendation
