import argparse
import os

import accloudtant


def parse():
    parser = argparse.ArgumentParser(description="Cloud Accountant.")
    parser.add_argument(
        "paths",
        nargs="*",
        default=".",
        help="List of paths to look for CSV files",
    )
    return parser.parse_args()


if __name__ == "__main__":
    args = parse()

    usage = accloudtant.usage_records.UsageRecords()

    for path in args.paths:
        for csv_file in accloudtant.find_csv_files(path):
            print("Processing", csv_file)
            usage.extend(accloudtant.process_file(csv_file))

    result = ""
    for service in usage.services():
        result += "{}\n".format(service)
        for area in usage.areas(service):
            result += "\t{}\n".format(area)

    if len(usage.data_transfers) > 0:
        result += "Data Transfer\n"
        for area in set([data.area for data in usage.data_transfers]):
            result += "\t{}\n".format(area)

    print(result.rstrip())
