import struct
import base64


def encode_hashes(version: int, starting_class: int, ascendency: int, fullscreen: int, hashes: list) -> str:
    """
    Creates a valid poe skilltree url payload
    :param version:
    :param starting_class:
    :param ascendency:
    :param fullscreen:
    :param hashes:
    :return:
    """
    # [ver,charclass,asc,[4byte ints]]
    bytes = bytearray(struct.pack('>ibbb', version, starting_class, ascendency, fullscreen))
    for tmpHash in hashes:
        for byte in struct.pack('>H', tmpHash):
            bytes.append(byte)
    return base64.urlsafe_b64encode(bytes).decode("utf-8")