<?php

namespace App\Modules\Admin\Billing\Services;

/**
 * Records failed payment signals for future PSP webhooks (Stripe, etc.).
 * Does not change subscription state — callers orchestrate grace / dunning.
 */
class BillingFailedPaymentService
{
    public function __construct(
        private readonly BillingAuditService $billingAudit,
    ) {}

    /**
     * @param  array<string, mixed>  $meta
     */
    public function record(int $tenantId, ?int $actorUserId, array $meta = []): void
    {
        if ($actorUserId !== null) {
            $this->billingAudit->log($actorUserId, $tenantId, 'payment.failed_recorded', $meta);
        } else {
            $this->billingAudit->logSystem($tenantId, 'payment.failed_recorded', $meta);
        }
    }
}
