<?php

declare(strict_types=1);

namespace ImovelZapAi\Importing\Application\Queries;

use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use ImovelZapAi\Importing\Infrastructure\Persistence\Eloquent\ImportJobModel;

final class ListImportsQuery
{
    /**
     * @param  array{status?: string|null, per_page?: int}  $filters
     */
    public function execute(string $tenantId, array $filters = []): LengthAwarePaginator
    {
        $query = ImportJobModel::query()
            ->where('tenant_id', $tenantId)
            ->with('file')
            ->latest();

        if (! empty($filters['status'])) {
            $query->where('status', $filters['status']);
        }

        return $query->paginate((int) ($filters['per_page'] ?? 15));
    }
}
