from backend.Property import Property


class DraughtProofingRecommendations:

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

        self.recommendation = []

    def recommend(self):
        """
        In some cases, we can identify the need for draught proofing from the EPC recommendations, however the initial
        implementation of this class will just assume that we are picking up a non-invasive recommendation from the
        survey
        """

        # For the moment, draught proofing doesn't have a phase impact

        draught_proofing_recommendation_config = next(
            (r for r in self.property.non_invasive_recommendations if
             r["type"] == "draught_proofing"),
            {}
        )

        if not draught_proofing_recommendation_config:
            return

        # Cost is based on a £50 cost per window, based on Checkatrade
        cost = draught_proofing_recommendation_config.get("cost", self.property.number_of_windows * 50)

        description = (
            "Draught proof doors and windows to improve energy efficiency" if
            not draught_proofing_recommendation_config.get("description")
            else draught_proofing_recommendation_config["description"]
        )

        # We recommend installing two mechanical ventilation systems
        self.recommendation = [
            {
                "phase": None,
                "parts": [],
                "type": "draught_proofing",
                "measure_type": "draught_proofing",
                "description": description,
                "starting_u_value": None,
                "new_u_value": None,
                "already_installed": False,
                "sap_points": draught_proofing_recommendation_config["sap_points"],
                "heat_demand": 0,
                "kwh_savings": 0,
                "co2_equivalent_savings": 0,
                "energy_cost_savings": 0,
                "total": cost,
                # We use a very simple and rough estimate of 4 hours per unit
                "labour_hours": draught_proofing_recommendation_config.get("labour_hours", 8),
                "labour_days": draught_proofing_recommendation_config.get("labour_days", 1),  # Assume 8 hour day
                "survey": True
            }
        ]
