<?php

namespace App\Modules\Admin\ActivityLog\DTOs;

use Illuminate\Support\Str;

final readonly class ActivityLogWriteData
{
    public function __construct(
        public int $tenantId,
        public ?int $userId,
        public string $module,
        public string $action,
        public string $entityType,
        public ?int $entityId,
        public string $description,
    ) {}

    /**
     * @return array<string, mixed>
     */
    public function toAttributes(?string $ip, ?string $userAgent): array
    {
        $ua = $userAgent !== null ? Str::limit($userAgent, 65000, '') : null;

        return [
            'tenant_id' => $this->tenantId,
            'user_id' => $this->userId,
            'module' => $this->module,
            'action' => $this->action,
            'entity_type' => $this->entityType,
            'entity_id' => $this->entityId,
            'description' => Str::limit($this->description, 500, ''),
            'ip_address' => $ip,
            'user_agent' => $ua,
        ];
    }
}
