
def build_version(version_list, phase="", project_name="",):
    major, minor, patch, build = version_list

    if type(version_list) == list:
        version_list = tuple(version_list)

    version_data = {
        "major": major,
        "minor": minor,
        "patch": patch,
        "build": build,
        "phase": phase,
    }

    if phase and build:
        version = f"{major}.{minor}.{patch}{phase}{build}"
    else:
        version = f"{major}.{minor}.{patch}"

    phase_names = {
        "a": "Alpha",
        "b": "Beta",
        "": "Stable",
    }

    phase_display = phase_names.get(phase, "Stable")

    if project_name:
        if phase:
            project_display = f"{phase_display}-{project_name}"
        else:
            project_display = project_name
    else:
        project_display = phase_display

    version_display = (
        f"{version} ({phase_display})"
        if phase
        else version
    )

    return {
        "__versionList__": version_list,
        "__versionData__": version_data,
        "__version__": version,
        "__versionDisplay__": version_display,
        "__projectName__": project_display,
    }
