<?php
declare(strict_types=1);

namespace App\Models;

use App\Core\Database;

final class CustomerUser
{
    public static function findActive(int $id): ?array
    {
        return Database::instance()->fetch(
            "SELECT * FROM customer_users WHERE id = :id AND status = 'active'",
            ['id' => $id]
        );
    }

    public static function findByEmail(string $email): ?array
    {
        return Database::instance()->fetch(
            'SELECT * FROM customer_users WHERE email = :e LIMIT 1',
            ['e' => $email]
        );
    }

    public static function markLogin(int $id): void
    {
        Database::instance()->query(
            'UPDATE customer_users SET last_login_at = NOW() WHERE id = :id',
            ['id' => $id]
        );
    }
}
