import pandas as pd

from utils.s3 import save_csv_to_s3

USER_ID = 8
PORTFOLIO_ID = 100


def app():
    """
    This function sets up an asset list with just a few properties to model the impact of the following scenarios:
    1) EWI
    2) EWI + Solar
    3) EWI + Solar + ASHP
    :return:
    """

    asset_list = [
        # This is an example of a low D - SAP score is 60
        {
            "address": "37, Birling Road",
            "postcode": "DA8 3JQ",
            "uprn": 100020225444
        },
        {
            "address": "16, Brasted Road",
            "postcode": "DA8 3HU",
            "uprn": 100020225805
        },
        {
            "address": "25, Birling Road",
            "postcode": "DA8 3JQ",
            "uprn": 100020225432,
        },
        {
            "address": "4, Halstead Road",
            "postcode": "DA8 3HX",
            "uprn": 100020229555
        }
    ]
    asset_list = pd.DataFrame(asset_list)

    filename = f"{USER_ID}/{PORTFOLIO_ID}/pilot.csv"
    save_csv_to_s3(
        dataframe=asset_list,
        bucket_name="retrofit-plan-inputs-dev",
        file_name=filename
    )

    non_invasive_recs = []
    for _, al in asset_list.iterrows():
        solar_rec = {
            "type": "solar_pv",
            "suitable": True,
            "array_wattage": 4000,
            "initial_ac_kwh_per_year": 3800,
            "cost": 4009,
            "panneled_roof_area": 20  # Rough estimate for 10 panels, around 1m x 1.8m (accomodate gaps and 30cm edge)
        }

        non_invasive_recs.append({
            "uprn": al["uprn"],
            "recommendations": [solar_rec],
        })

    # Store non-invasive recommendations in S3
    non_invasive_recommendations_filename = f"{USER_ID}/{PORTFOLIO_ID}/non_invasive_recommendations.csv"
    save_csv_to_s3(
        dataframe=pd.DataFrame(non_invasive_recs),
        bucket_name="retrofit-plan-inputs-dev",
        file_name=non_invasive_recommendations_filename
    )

    body1 = {
        "portfolio_id": str(PORTFOLIO_ID),
        "housing_type": "Private",
        "goal": "Increasing EPC",
        "goal_value": "A",
        "trigger_file_path": filename,
        "already_installed_file_path": "",
        "patches_file_path": "",
        "non_invasive_recommendations_file_path": "",
        "scenario_name": "ECO4 funding - EWI",
        "multi_plan": True,
        "exclusions": [
            "internal_wall_insulation",
            "roof_insulation", "ventilation", "floor_insulation", "windows", "fireplace", "heating", "hot_water",
            "lighting", "secondary_heating", "solar_pv"
        ],
        "budget": None,
    }
    print(body1)

    body2 = {
        "portfolio_id": str(PORTFOLIO_ID),
        "housing_type": "Private",
        "goal": "Increasing EPC",
        "goal_value": "A",
        "trigger_file_path": filename,
        "already_installed_file_path": "",
        "patches_file_path": "",
        "non_invasive_recommendations_file_path": non_invasive_recommendations_filename,
        "scenario_name": "ECO4 funding - EWI + Solar",
        "multi_plan": True,
        "exclusions": [
            "internal_wall_insulation",
            "roof_insulation",
            "ventilation",
            "floor_insulation",
            "windows",
            "fireplace",
            "heating",
            "hot_water",
            "lighting",
            "secondary_heating",
            "boiler_upgrade",
            "high_heat_retention_storage_heaters",
        ],
        "budget": None,
    }
    print(body2)

    body3 = {
        "portfolio_id": str(PORTFOLIO_ID),
        "housing_type": "Private",
        "goal": "Increasing EPC",
        "goal_value": "A",
        "trigger_file_path": filename,
        "already_installed_file_path": "",
        "patches_file_path": "",
        "non_invasive_recommendations_file_path": non_invasive_recommendations_filename,
        "scenario_name": "ECO4 funding - EWI + Solar + ASHP",
        "multi_plan": True,
        "exclusions": [
            "internal_wall_insulation",
            "roof_insulation", "ventilation", "floor_insulation", "windows", "fireplace", "hot_water",
            "lighting", "secondary_heating",
        ],
        "budget": None,
    }
    print(body3)
