from hledger_tools.resources import Entry, Loan, Mark, Posting


def make_loan_entries(loan: Loan, cash: list[str], expense: list[str], liability: list[str]) -> list[Entry]:
    payments = loan.payment_schedule().values()

    entries: list[Entry] = list()
    for payment in payments:
        postings: list = list()

        postings.append(
            Posting(
                account=cash,
                amount=payment.amount * -1,
                comment="",
            )
        )
        postings.append(
            Posting(
                account=expense,
                amount=payment.interest,
                comment="",
            )
        )
        postings.append(
            Posting(
                account=liability,
                amount=payment.principal,
                comment="",
            )
        )

        entries.append(
            Entry(
                date=payment.term,
                status=Mark.UNMARKED,
                code="",
                description=loan.name,
                comment="",
                postings=postings,
            )
        )

    return entries
