import pytest
import datetime
from backend.Property import Property
from recommendations.FireplaceRecommendations import FireplaceRecommendations
from etl.epc.Record import EPCRecord


@pytest.fixture
def fireplace_materials():
    return [
        {'id': 3591, 'type': 'sealing_fireplace', 'description': 'Sealing of an open fireplace', 'depth': 0.0,
         'depth_unit': None, 'cost': None, 'cost_unit': 'gbp_per_unit', 'r_value_per_mm': None,
         'r_value_unit': 'square_meter_kelvin_per_watt', 'thermal_conductivity': None,
         'thermal_conductivity_unit': None, 'link': 'Warm Front',
         'created_at': datetime.datetime(2025, 8, 15, 16, 31, 52, 995292), 'is_active': True,
         'prime_material_cost': None, 'material_cost': 0.0, 'labour_cost': 0.0, 'labour_hours_per_unit': 0.0,
         'plant_cost': 0.0, 'total_cost': 185.0, 'notes': None, 'is_installer_quote': True, 'innovation_rate': 0.0,
         'size': None, 'size_unit': None, 'includes_scaffolding': False, 'includes_battery': False,
         'battery_size': None}
    ]


class TestFirepaceRecommendations:

    def test_no_fireplaces(self, fireplace_materials):
        epc_record = EPCRecord()
        epc_record.number_open_fireplaces = 0
        property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
        recommender = FireplaceRecommendations(property_instance=property_instance, materials=fireplace_materials)
        assert recommender.recommendation is None
        recommender.recommend()
        assert recommender.recommendation is None

    def test_one_fireplace(self, fireplace_materials):
        epc_record = EPCRecord()
        epc_record.number_open_fireplaces = 1
        property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
        property_instance.already_installed = []
        recommender = FireplaceRecommendations(property_instance=property_instance, materials=fireplace_materials)
        assert recommender.recommendation is None
        recommender.recommend()
        assert recommender.recommendation
        assert recommender.recommendation[0]["type"] == "sealing_open_fireplace"
        assert recommender.recommendation[0]["total"] == 185

    def test_multiple_fireplaces(self, fireplace_materials):
        epc_record = EPCRecord()
        epc_record.number_open_fireplaces = 3
        property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
        property_instance.already_installed = []
        recommender = FireplaceRecommendations(property_instance=property_instance, materials=fireplace_materials)
        assert recommender.recommendation is None
        recommender.recommend()
        assert recommender.recommendation
        assert recommender.recommendation[0]["type"] == "sealing_open_fireplace"
        assert recommender.recommendation[0]["total"] == 185 * 3
