import csv
from pathlib import Path

from accloudtant.usage_record import UsageRecord
from accloudtant.usage_records import UsageRecords


def find_csv_files(path='.'):
    p = Path(path)
    if p.is_file() and p.parts[-1].endswith(".csv"):
        return [p]
    return list(p.glob('**/*.csv'))


def process_file(csv_file):
    rows = UsageRecords()

    with open(csv_file) as f:
        csv_reader = csv.DictReader(f)
        for row in csv_reader:
            rows.append(UsageRecord(row))

    return rows
