import logging


def process_covid_json_data(covid_json_data:list) -> tuple:
    """Returns cases in last 7 days, current hospitalisations,
    and total deaths from covid json data"""

    if not covid_json_data:
        logging.error("No json data was recieved")
        return 0, 0, 0

    #Adds up cases for data entries representing the last 7 days
    cases_last_7 = 0
    for i in range(3, 10):
        if covid_json_data[i]["newCases"] is not None:
            cases_last_7 += covid_json_data[i]["newCases"]

    hospital_cases = 0
    i = 1
    #Searches through data entries until it finds one with the latest hospital cases
    while hospital_cases == 0 and i < len(covid_json_data):
        hospital_cases = covid_json_data[i]["hospitalCases"]
        if hospital_cases is None:
            hospital_cases = 0
        else:
            hospital_cases = int(hospital_cases)
        i += 1

    #Searches through data entries until it finds one with the latest death count
    total_deaths = 0
    i = 1
    while total_deaths == 0 and i < len(covid_json_data):
        total_deaths = covid_json_data[i]["cumDeaths"]
        if total_deaths is None:
            total_deaths = 0
        else:
            total_deaths = int(total_deaths)
        i += 1

    return cases_last_7, hospital_cases, total_deaths