import requests


def get_filesize(pql_query: str,
                 datatype: str = "ssm") -> int:
    """
    Calls an ICGC Data Portal API to retrieve the file size of the dataset
    specified by a PQL query and a data type.

    :param pql_query: PQL query to retrieve the dataset of interest.
    :param datatype: data types e.g., "ssm" for simple somatic mutation,
        "donor" for clinical dataset, "cnsm" for copy number somatic mutation,
        etc.
    :return: size of the specified dataset in bytes.
    """
    url = f"https://dcc.icgc.org/api/v1/download/sizePQL?pql={pql_query}"

    response = requests.get(url)
    if response.status_code != 200:
        raise IOError(f"GET {url} resulted in status code {response.status_code}")

    file_sizes = response.json()["fileSize"]
    for dataset in file_sizes:
        if dataset["label"] == datatype:
            return dataset["sizes"]

    raise ValueError(f"GET {url} does not contain the {datatype} data type.")