from typing import List
import re


def get_names_and_values_of_lines(lines: List[str]) -> dict:
    """
    All unnecessary code is deleted (annotations, doc).
    Only the name of the variable and the value is extracted.

    :param List[str] lines:
        List of strings with lines from a modelica file.

    :return:
        dict: Containing the names as key and values as value.

    Example:

    >>> lines = ['parameter Boolean my_boolean=true "Some description"',
    >>>          'parameter Real my_real=12.0 "Some description" annotation("Some annotation")']
    >>> output = get_names_and_values_of_lines(lines=lines)
    >>> print(output)
    {'my_boolean': True, 'my_real': 12.0}
    """
    res = {}
    for line in lines:
        line = line.replace(";", "")

        # Check if line is a commented line and if so, skip the line:
        if line.startswith("//"):
            continue

        # Remove part behind possible annotation:
        loc = line.find("annotation")
        if loc >= 0:
            line = line[:loc]
        # Remove possible brackets, like "param(min=0, start=5)
        line = re.sub(r'[\(\[].*?[\)\]]', '', line)
        # And now any quotes / doc / strings
        line = re.sub(r'".*"', '', line)
        # If a value is present (e.g. for parameters, one = sign is still present (always)
        if line.find("=") >= 0:
            name_str, val_str = line.split("=")
            name_str = name_str.strip()
            name = name_str.split(" ")[-1].replace(" ", "")
            val_str_stripped = val_str.replace(" ", "")
            if val_str_stripped in ["true", "false"]:
                value = val_str_stripped == "true"
            else:
                try:
                    value = float(val_str_stripped)
                except ValueError:
                    # Neither float, integer nor boolean, hence None
                    value = None
        # else no value is stored in the line
        else:
            line = line.strip()
            name = line.split(" ")[-1].replace(" ", "")
            value = None
        res.update({name: value})

    return res