from bs4 import BeautifulSoup


def extract_feature_counts(html_summary: str) -> tuple:
    """Extract features counts from html summary using BeautifulSoup.

    If the html_summary from a raster dataset is supplied, there won't be any
    feature counts. An IndexError exception is caught and a tuple containing
    'None' values is returned.

    Parameters
    ----------
    html_summary : str
        The dataset update summary component from the LINZ Data Service Atom
        feed.

    Returns
    -------
    tuple
        (total_features, adds, modifies, deletes, total_changes)
    """
    soup = BeautifulSoup(html_summary, features="html.parser")
    feature_counts = soup.find_all("td")

    try:
        total_features = feature_counts[0].string
        adds = feature_counts[1].string
        modifies = feature_counts[2].string
        deletes = feature_counts[3].string
    except IndexError:
        return (None, None, None, None, None)

    total_changes = int(adds) + int(modifies) + int(deletes)

    return (total_features, adds, modifies, deletes, total_changes)