<?php

namespace App\Services\Payments;

use App\Models\PaymentLog;

class PaymentLogger
{
    public function log(string $gateway, string $logType, string|array $payload, ?string $externalId = null): PaymentLog
    {
        $body = is_array($payload) ? json_encode($payload) : $payload;

        return PaymentLog::create([
            'gateway' => $gateway,
            'log_type' => $logType,
            'external_id' => $externalId,
            'payload' => $body,
        ]);
    }
}
