from typing import Any
from typing import Dict


def get_sample_details(
    group_by: str, mongo_reader: Any, database: str
) -> Dict[Any, Dict[str, Any]]:
    """
    Get details from the samples collection.  Use this to decide which samples to query data for.

    Args:
        group_by: the name of the key to group samples by (Category-based key)
        mongo_reader: the mongo wrapper
        database: the database to use

    Returns:
        details required for each sample available.

    """

    sample_details = {}
    search = {group_by: {"$exists": True}}
    sample_grouping = mongo_reader.find_as_cursor(
        database,
        "samples",
        query=search,
        projection={"_id": 0, group_by: 1, "sample_name": 1, "Description": 1},
    )

    for sample in sample_grouping:
        sample_details[sample["sample_name"]] = {
            "description": sample["Description"]
            if "Description" in sample
            else sample["sample_name"],
            "category": sample[group_by],
        }

    return sample_details