from recommendations.Costs import Costs
from recommendations.recommendation_utils import override_costs
from backend.Property import Property


class SecondaryHeating:
    """
    This class recommends the removal of the secondary heating system for properties that have a primary heating
    system.
    """

    def __init__(self, property_instance: Property):
        self.property = property_instance
        self.costs = Costs(self.property)

        self.recommendation = []

    def recommend(self, phase: int):
        # Reset
        self.recommendation = []
        if self.property.epc_record.secondheat_description in ["None", None] or (
            "sap05" in self.property.epc_record.secondheat_description.lower()
        ):
            # No secondary heating system, so no recommendation to remove it
            return

        if self.property.epc_record.number_habitable_rooms > self.property.epc_record.number_heated_rooms:
            n_rooms = self.property.epc_record.number_habitable_rooms - self.property.epc_record.number_heated_rooms
        else:
            n_rooms = self.property.epc_record.number_heated_rooms

        costs = self.costs.heater_removal(n_rooms=n_rooms)

        already_installed = "secondary_heating" in self.property.already_installed
        if already_installed:
            costs = override_costs(costs)
            description = "Secondary heating system has already been removed, no further action required"
        else:
            description = "Remove the secondary heating system"

        self.recommendation.append(
            {
                "phase": phase,
                "parts": [],
                "type": "secondary_heating",
                "measure_type": "secondary_heating",
                "description": description,
                "starting_u_value": None,
                "new_u_value": None,
                "sap_points": None,
                "already_installed": already_installed,
                **costs,
                "simulation_config": {
                    "secondheat_description_ending": "None"
                },
                "description_simulation": {
                    "secondheat-description": "None"
                },
                "innovation_rate": 0.0,  # No innovation rate for this measure
            }
        )
