<?php
namespace App\Models;

use App\Core\Model;
use PDO;

class User extends Model {
    protected static string $table = 'users';

    public static function findByEmail(string $email): ?array {
        return self::firstWhere('email', $email);
    }

    public static function updateLastLogin(int $userId): void {
        $stmt = self::db()->prepare("UPDATE users SET last_login = NOW() WHERE id = ?");
        $stmt->execute([$userId]);
    }

    public static function getActiveAgents(): array {
        $stmt = self::db()->query("SELECT id, name, email, role, avatar FROM users WHERE status = 'active' ORDER BY name ASC");
        return $stmt->fetchAll();
    }
}
