<?php

namespace App\Modules\HR\Employees\Services;

use App\Models\User;
use App\Modules\Admin\ActivityLog\DTOs\ActivityLogWriteData;
use App\Modules\Admin\ActivityLog\Services\ActivityLogService;
use App\Modules\HR\Employees\Models\Employee;

class EmployeeProfileActivityLogger
{
    public function __construct(
        private readonly ActivityLogService $activityLog,
    ) {}

    public function log(Employee $employee, string $action, string $description): void
    {
        $tenantId = (int) $employee->tenant_id;
        if ($tenantId === 0) {
            return;
        }

        $user = auth()->user();
        $this->activityLog->log(new ActivityLogWriteData(
            tenantId: $tenantId,
            userId: $user instanceof User ? $user->id : null,
            module: 'hr',
            action: $action,
            entityType: Employee::class,
            entityId: $employee->id,
            description: $description,
        ));
    }
}
