from BaseUtility import Definitions
from backend.Property import Property


class FireplaceRecommendations(Definitions):
    """
    For properties that have open fireplaces, we recommend sealing the fireplaces
    """

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

        self.has_ventilaion = None
        self.recommendation = None
        self.materials = [m for m in materials if m["type"] == "sealing_fireplace"]
        if len(self.materials) != 1:
            raise ValueError("Incorrect number of sealing fireplace materials specified")

    def recommend(self, phase=0):
        """
        Based on the number of open fireplcaes found, we recommend sealing each one at a cost of
        around £500
        :return:
        """

        number_open_fireplaces = self.property.epc_record.number_open_fireplaces

        if number_open_fireplaces == 0:
            return

        material = self.materials[0]

        already_installed = "sealing_open_fireplace" in self.property.already_installed
        estimated_cost = number_open_fireplaces * material["total_cost"] if not already_installed else 0

        # We recommend installing two mechanical ventilation systems
        self.recommendation = [
            {
                "phase": phase,
                "parts": [material],
                "type": "sealing_open_fireplace",
                "measure_type": "sealing_open_fireplace",
                "description": "Seal %s open fireplaces" % str(number_open_fireplaces),
                "starting_u_value": None,
                "new_u_value": None,
                "sap_points": None,
                "already_installed": already_installed,
                "total": estimated_cost,
                # Take a very basic estimate of 6 hours, multipled by the number of open fireplaces to seal
                "labour_hours": 6 * number_open_fireplaces,
                "labour_days": 6 * number_open_fireplaces / 8,  # Assume 8 hour day
                "description_simulation": {
                    "number-open-fireplaces": 0
                },
                "innovation_rate": material["innovation_rate"],
            }
        ]
