<?php

namespace App\Services;

use App\Models\User;
use App\Models\Website;
use App\Repositories\ActivityLogRepository;
use Illuminate\Http\Request;

class AuditLogService
{
    public function __construct(
        protected ActivityLogRepository $activityLogs,
        protected Request $request,
    ) {
    }

    public function record(
        string $category,
        string $action,
        string $description,
        ?Website $website = null,
        ?User $user = null,
        array $meta = [],
    ): void {
        $this->activityLogs->create([
            'user_id' => $user?->id ?? $this->request->user()?->id,
            'website_id' => $website?->id,
            'category' => $category,
            'action' => $action,
            'description' => $description,
            'ip_address' => $this->request->ip(),
            'user_agent' => $this->request->userAgent(),
            'meta' => $meta,
            'occurred_at' => now(),
        ]);
    }
}
