from typing import List
from typing import Dict
import tempfile
import csv


def write_output_csv(transactions: List[Dict[str, str]]) -> str:
    """
    Write the temporary output CSV file for Ledger to convert.

    :param transactions: List of transactions to add to CSV
    :return: Path to output CSV file
    :rtype: str
    """

    # pylint: disable=line-too-long
    with tempfile.NamedTemporaryFile('w', prefix='ledger-', suffix='.csv', newline='', delete=False) as fp:
        output_writer = csv.DictWriter(
            fp,
            dialect=csv.unix_dialect,
            fieldnames=[
                'amount',
                'date',
                'description',
                'note'
            ]
        )

        output_writer.writeheader()

        for row in transactions:
            output_writer.writerow({
                'amount': row['amount'],
                'date': row['date'],
                'description': row['description'],
                'note': row['type']
            })

    return fp.name