/**
* Internal function to execute the command.
*
* @param InputInterface $input The input to inject into the command.
* @param OutputInterface $output The output to inject into the command.
*
* @return integer The command exit code
*
* @since 4.1.0
* @throws \Exception
*/
protected function doExecute(InputInterface $input, OutputInterface $output) : int
{
Factory::getApplication()->getLanguage()->load('joomla', JPATH_ADMINISTRATOR);
$this->configureIO($input, $output);
$this->ioStyle->title('List Scheduled Tasks');
$tasks = array_map(function (\stdClass $task) : array {
$enabled = $task->state === 1;
$nextExec = Factory::getDate($task->next_execution, 'UTC');
$due = $enabled && $task->taskOption && Factory::getDate('now', 'UTC') > $nextExec;
return ['id' => $task->id, 'title' => $task->title, 'type' => $task->safeTypeTitle, 'state' => $task->state === 1 ? 'Enabled' : ($task->state === 0 ? 'Disabled' : 'Trashed'), 'next_execution' => $due ? 'DUE!' : $nextExec->toRFC822()];
}, $this->getTasks());
$this->ioStyle->table(['id', 'title', 'type', 'state', 'next run'], $tasks);
return 0;
}