from typing import Dict
from typing import Any
from typing import Tuple
from typing import List


def get_category_counts(cookie_data: Dict[str, Dict[str, Any]]) -> Dict[Tuple[str,str], List[int]]:
    """
    Retrieve category counts for each cookie, to then be able to compute the majority opinion.
    Cookies are identified by (name, domain).
    @param cookie_data: Storage for the cookie data, needs to contain "name", "domain", "label"
    @return: Dictionary of category counts per cookie identifier, keys being (name, domain)
    """
    # for each cookie and domain, set up an array of category counts, and update the array
    label_by_ident_dict: Dict[Tuple[str, str], List[int]] = dict()

    for _, entry in cookie_data.items():

        c_cat = entry["label"]

        key = (entry["name"], entry["domain"])
        if key in label_by_ident_dict:
            cat_list = label_by_ident_dict[key]
        else:
            # ne, fu, an, ad, uncat, socmedia, unknown
            cat_list = [0, 0, 0, 0, 0, 0, 0]
            label_by_ident_dict[key] = cat_list

        # increment the counters
        cat_id = int(c_cat)
        if 0 <= cat_id < 5:
            cat_list[cat_id] += 1
        elif cat_id == -1:
            cat_list[6] += 1
        elif cat_id == 99:
            cat_list[5] += 1

    return label_by_ident_dict