"""Module used to run the wind forecast generation tool which allows users to build a custom wind
forecast.
"""

import json

from .utilities.file_io import WindForecastGen

def save_wind_output(data: dict):
    """Function called after user is finished entering wind forecast data in GUI. Parses the input
    data and saves it into the required .json format for wind forecasts.

    :param data: dictionary generated by GUI containing the time step, speeds and directions for
    the wind forecast.
    :type data: dict
    """
    forecast = data['forecast']
    time_step = data['time_step']
    filepath = data['save_location']

    wind_data = [{'direction': float(dir), "speed_m_s": float(speed)} for speed, dir in forecast]

    json_output = {"time_step_min": time_step, "data": wind_data}

    with open(filepath, 'w') as json_file:
        json.dump(json_output, json_file, indent=4)

def main():
    wind_generator = WindForecastGen(save_wind_output)
    wind_generator.run()

if __name__ == "__main__":
    main()
