import csv
from dataclasses import asdict

from app.routes import FilterConfig, forderung_filter_config


def export_filter_config():
    with open("filter_config.csv", "w", newline="", encoding="latin-1") as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=asdict(forderung_filter_config[0]).keys(), delimiter=";")
        writer.writeheader()
        writer.writerows([asdict(config) for config in forderung_filter_config])


# name	filter_type	width	text	key_column	value_column	sort_column	default_value


def import_filter_config2():
    with open("forderungen\\liste\\config\\liste_filter.csv", "r", newline="", encoding="latin-1") as csvfile:
        reader = csv.DictReader(csvfile, delimiter=";")
        for row in reader:
            # Convert the row dictionary to a FilterConfig object
            config = FilterConfig.from_dict(*row.values())
            print(config)


if __name__ == "__main__":
    import_filter_config2()
