<?php

namespace App\EventHooks\Client;

use App\EventHooks\HookEvent;
use App\Models\User;

/**
 * Fire noktası: UserObserver::created → buildUserContext.
 * Context: user (model), userid/user_id, email. Model = App\Models\User
 * (WHMCS-parity 'user' tablosu; admin-login modeli App\Models\Admin ile
 * KARIŞTIRMA — login event'leri Admin döndürür).
 */
class UserAdded extends HookEvent
{
    public const HOOK = 'UserAdd';

    public function user(): ?User
    {
        $u = $this->get('user') ?? $this->get('admin');
        if ($u instanceof User) {
            return $u;
        }
        $id = $this->get('user_id') ?? $this->get('userid');

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