<?php

namespace App\EventHooks\Client;

use App\EventHooks\HookEvent;
use App\Models\Admin;

/**
 * Fire noktası: AuthenticatedSessionController::store (admin guard login).
 * Context: admin (model), userid/user_id, username, ipaddress. 'user' anahtarı
 * YOK — admin guard provider App\Models\Admin'dir (App\Models\User DEĞİL;
 * o WHMCS-parity sub-user kavramı, UserObserver'da kullanılır).
 */
class AdminUserLoggedIn extends HookEvent
{
    public const HOOK = 'UserLogin';

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

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

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

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