from typing import Optional


def get_result_state(code: int) -> Optional[str]:
    """Translate an result state code to a human-readable state.

    Official mapping is available
    `here <https://github.com/BOINC/boinc/blob/master/py/Boinc/boinc_db.py>`.

    Args:
      code:
        The code of result state.

    Returns:
      The human-readable state related to the code.
    """

    states = {
        0: "NEW",
        1: "FILES_DOWNLOADING",
        2: "FILES_DOWNLOADED",
        3: "COMPUTE_ERROR",
        4: "FILES_UPLOADING",
        5: "FILES_UPLOADED",
        6: "ABORTED",
        7: "UPLOAD_FAILED",
    }
    return states.get(int(code))