<?php

namespace App\Modules\Admin\ActivityLog\Services;

use App\Modules\Admin\ActivityLog\Repositories\ActivityLogRepository;
use App\Modules\Admin\Tenancy\Repositories\TenantRepository;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

class ActivityLogReadService
{
    public function __construct(
        private readonly ActivityLogRepository $logs,
        private readonly TenantRepository $tenants,
    ) {}

    /**
     * @param  array{tenant_id?: int|null, module?: string|null, action?: string|null}  $filters
     * @return array{logs: LengthAwarePaginator, tenantOptions: array<int|string, mixed>, moduleOptions: array<string, string>, actionOptions: array<string, string>}
     */
    public function indexPage(array $filters): array
    {
        return [
            'logs' => $this->logs->paginate($filters),
            'tenantOptions' => $this->tenants->idNamePairsOrdered(),
            'moduleOptions' => $this->logs->distinctModuleLabels(),
            'actionOptions' => $this->logs->distinctActionLabels(),
        ];
    }
}
