from pathlib import Path
from typing import Tuple
from typing import List
from typing import Dict
from typing import Set
from typing import Sequence
import csv


def __read_explicit_concepts(
    concepts_path: Path
) -> Tuple[List[Dict[str, str]], Set[str], Sequence[str]]:
    """Read content, concepts and fieldnames defined in source concepts.csv."""
    with open(concepts_path, "r") as concepts_csv:
        concepts_reader = csv.DictReader(concepts_csv)
        concept_csv_content = list()
        explicit_concepts = set()
        if concepts_reader.fieldnames:
            concept_fields = concepts_reader.fieldnames
        else:
            raise EnvironmentError(f"{concepts_path} is not a correct concept CSV file.")
        for row in concepts_reader:
            concept_csv_content.append(row)
            explicit_concepts.add(row["name"])

    return (concept_csv_content, explicit_concepts, concept_fields)