<?php

namespace App\EventHooks\Invoice;

use App\EventHooks\HookEvent;
use App\Models\Transaction;

/**
 * Fire noktası: PaymentManager::handleCallback → LogTransaction
 * Context: gateway, data (callback payload), result. Transaction modeli/amount
 * taşınmaz → transaction()/amount() bu fire noktasında null döner.
 */
class TransactionLogged extends HookEvent
{
    public const HOOK = 'LogTransaction';

    public function transaction(): ?Transaction
    {
        $t = $this->get('transaction');
        if ($t instanceof Transaction) {
            return $t;
        }
        $id = $this->get('transaction_id') ?? $this->get('id');

        return $id ? Transaction::find($id) : null;
    }

    public function amount(): mixed
    {
        return $this->get('amount');
    }

    public function gateway(): ?string
    {
        return $this->get('gateway');
    }
}
