<?php

namespace App\Modules\HR\Attendance\Services;

use App\Modules\Admin\ActivityLog\DTOs\ActivityLogWriteData;
use App\Modules\Admin\ActivityLog\Services\ActivityLogService;
use App\Modules\HR\Attendance\Models\AttendanceRecord;

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

    public function log(AttendanceRecord $record, string $action, int $userId, string $description): void
    {
        $tenantId = (int) $record->tenant_id;
        if ($tenantId < 1) {
            return;
        }

        $this->activityLog->log(new ActivityLogWriteData(
            tenantId: $tenantId,
            userId: $userId > 0 ? $userId : null,
            module: 'hr',
            action: $action,
            entityType: AttendanceRecord::class,
            entityId: (int) $record->id,
            description: $description,
        ));
    }
}
