<?php

namespace App\Services;

use Illuminate\Support\Facades\DB;

class UserActivityService
{
    public function heartbeat(int $userId, ?int $schoolId, ?string $page = null): void
    {
        DB::table('user_heartbeats')->updateOrInsert(
            ['user_id' => $userId],
            [
                'school_id' => $schoolId,
                'last_seen_at' => now(),
                'ip_address' => request()->ip(),
                'user_agent' => request()->userAgent(),
                'page' => $page,
                'updated_at' => now(),
                'created_at' => now(),
            ]
        );
    }
}
