Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ListWorkflowsQuery
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Automation\Application\Queries;
6
7use Illuminate\Contracts\Pagination\LengthAwarePaginator;
8use ImovelZapAi\Automation\Infrastructure\Persistence\Eloquent\AutomationWorkflowModel;
9
10final class ListWorkflowsQuery
11{
12    /**
13     * @param  array{status?: string, per_page?: int}  $filters
14     */
15    public function execute(string $tenantId, array $filters = []): LengthAwarePaginator
16    {
17        $query = AutomationWorkflowModel::query()
18            ->where('tenant_id', $tenantId)
19            ->with(['triggers', 'conditions', 'actions'])
20            ->withCount('executions')
21            ->orderByDesc('updated_at');
22
23        if (! empty($filters['status'])) {
24            $query->where('status', $filters['status']);
25        }
26
27        return $query->paginate((int) ($filters['per_page'] ?? 20));
28    }
29}