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


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

        self.recommendations = []

    def recommend(self, phase):
        """
        There are maybe a number of recommendations that are simultaneously applicable to the property.
        If this is true then the phase may need to be incrememnted from within this recommendation

        :param phase:
        :return:
        """
        # Reset the recommendations
        self.recommendations = []

        # This first iteration of the recommender will provide very basic recommendation
        # We recommend heating controls based on the main heating system

        # If there is no system present, but access to the mains, we

        if (
            (self.property.hotwater["heater_type"] in ["electric immersion"]) &
            (self.property.data["hot-water-energy-eff"] == "Very Poor") &
            (self.property.hotwater["no_system_present"] is None)
        ):
            self.recommend_tank_insulation(phase=phase)
            return

    def recommend_tank_insulation(self, phase):
        """
        If the home has a very poor hot water system, this is often indicative of a lack of insulation on the hot water
        tank. This is a very simple and cost effective improvement that can be made to the home.
        """

        recommendation_cost = self.costs.hot_water_tank_insulation()

        already_installed = "hot_water_tank_insulation" in self.property.already_installed
        if already_installed:
            recommendation_cost = override_costs(recommendation_cost)
            description = "Insulation tank has already been insulated, no further action required"
        else:
            description = "Insulate hot water tank"

        self.recommendations.append(
            {
                "phase": phase,
                "parts": [
                    # TODO
                ],
                "type": "hot_water_tank_insulation",
                "description": description,
                "starting_u_value": None,
                "new_u_value": None,
                "sap_points": None,
                "already_installed": already_installed,
                **recommendation_cost,
                "simulation_config": {"hot_water_energy_eff_ending": "Average"}
            }
        )
        return
