<?php

declare(strict_types=1);

namespace App\Modules\Ledger\Application;

use App\Modules\Ledger\Domain\LedgerEntry;

class LedgerService
{
    /**
     * @return array<int, LedgerEntry>
     */
    public function recentEntries(string $tenantId, string $memberId): array
    {
        return [
            new LedgerEntry(
                id: 'ledger-demo-1',
                tenantId: $tenantId,
                memberId: $memberId,
                entryType: 'payment',
                amount: 10.00,
                bookedAt: '2026-03-20 09:00:00',
                referenceType: 'payment',
                referenceId: 'payment-demo-1'
            ),
            new LedgerEntry(
                id: 'ledger-demo-2',
                tenantId: $tenantId,
                memberId: $memberId,
                entryType: 'consumption',
                amount: -2.50,
                bookedAt: '2026-03-20 10:30:00',
                referenceType: 'coffee_entry',
                referenceId: 'coffee-demo-1'
            ),
        ];
    }

    public function balanceForMember(string $tenantId, string $memberId): float
    {
        $balance = 0.0;

        foreach ($this->recentEntries($tenantId, $memberId) as $entry) {
            $balance += $entry->amount();
        }

        return $balance;
    }
}
