from typing import Dict
from typing import List
import csv


def read_temp_csv_data(filepath_temp: str) -> Dict[str, Dict[int, List[float]]]:
    """Return a mapping from the state to a mapping of the year to yearly data in the format
    [average temperature, precipitation, wildfire counts].

    Currently, the values for precipitation are wildfires counts are dummy values.

    Preconditions:
        - filepath refers to a csv file in the format of
          data/Annual_Temperature.csv
          (i.e., could be that file or a different file in the same format)
    """
    # ACCUMULATOR: The mapping from the state to its yearly data so far
    data_so_far = {}

    with open(filepath_temp) as file_temp:
        reader_temp = csv.reader(file_temp)

        # Skip the first 3 lines of the data
        for _ in range(0, 3):
            next(reader_temp)

        # Store the header containing the names of the states
        states = next(reader_temp)

        # Iterate through the header, skipping the 1st index, to map states to an empty dictionary,
        # which will map the year to the data about the average temp, precipitation, wildfire counts
        for i in range(1, len(states)):
            data_so_far[states[i]] = {}

        # Iterate through the remaining rows of the dataset
        for row in reader_temp:

            # The current year being processed
            year = int(row[0])

            # Iterate through each index of the row
            for i in range(1, len(row)):
                # The average temperature value of a state in the current year
                value_temp = float(row[i])

                # Create a mapping from the year to that year's data
                # in the format [average temp, precipitation, wildfires]
                data_so_far[states[i]][year] = [value_temp, 0, 0]  # The 0s are dummy values

    return data_so_far