from typing import Dict


def csv_pep_filter(p, **kwargs) -> Dict[str, str]:
    """
    CSV PEP filter, that returns Sample object representations

    This filter can save the CSVs to files, if kwargs include
    `sample_table_path` and/or `subsample_table_path`.

    :param peppy.Project p: a Project to run filter on
    """
    sample_table_path = kwargs.get("sample_table_path")
    subsample_table_path = kwargs.get("subsample_table_path")
    sample_table_repr = p.sample_table.to_csv(path_or_buf=sample_table_path)

    s = ""
    if sample_table_repr is not None:
        s += sample_table_repr
    if p.subsample_table is not None:
        subsample_table_repr = p.subsample_table.to_csv(
            path_or_buf=subsample_table_path
        )
        if subsample_table_repr is not None:
            s += subsample_table_repr

    return {"samples.csv": s}