<?php

namespace Signteer\Rest\Controller;

use Plainwork\Http\Request;
use Signteer\Core\Criteria\TaskCriteria;
use Signteer\Core\Finder\TaskFinder;

final class ListTasksController
{
    public $taskFinder = TaskFinder::class;

    public function __invoke(Request $request)
    {
        $ret = [];

        $sheetId = $request->getQueryParam('sheet');
        if (null === $sheetId) {
            return $ret;
        }

        $c = (new TaskCriteria())->whereSheetId('=', $sheetId);
        $ms = $this->taskFinder->find($c);

        foreach ($ms as $m){
            $a = [];
            $a['title'] = $m->getTitle();
            $a['spots'] = $m->getSpots();

            $ret[] = $a;
        }

        return $ret;
    }
}
