#!/usr/bin/env php
<?php
declare(strict_types=1);

/**
 * @author TJ Draper <tj@buzzingpixel.com>
 * @copyright 2019 BuzzingPixel, LLC
 * @license Apache-2.0
 */

use corbomite\di\Di;

define('ENTRY_POINT', 'app');
define('APP_BASE_PATH', __DIR__);
define('APP_VENDOR_PATH', APP_BASE_PATH . '/vendor');

putenv('DB_HOST=db');
putenv('DB_DATABASE=site');
putenv('DB_USER=site');
putenv('DB_PASSWORD=secret');
putenv('CORBOMITE_DB_DATA_NAMESPACE=corbomite\queue\data');
putenv('CORBOMITE_DB_DATA_DIRECTORY=./src/data');

require APP_VENDOR_PATH . '/autoload.php';

////////////////////////////////////////////////////////////////////////////////

use corbomite\queue\Noop;
use corbomite\queue\QueueApi;

function testAddToQueue() {
    /** @noinspection PhpUnhandledExceptionInspection */
    $queueApi = Di::get(QueueApi::class);

    $batchModel = $queueApi->makeActionQueueBatchModel([
        'name' => 'this_is_a_test',
        'title' => 'This is a Test',
        'items' => [
            $queueApi->makeActionQueueItemModel([
                'class' => Noop::class,
            ]),
            $queueApi->makeActionQueueItemModel([
                'class' => Noop::class,
            ]),
            $queueApi->makeActionQueueItemModel([
                'class' => Noop::class,
                'method' => 'noop',
                'context' => [
                    'stuff' => 'thing',
                ],
            ]),
        ],
        'context' => [
            'test' => 'thing',
        ],
    ]);

    /** @noinspection PhpUnhandledExceptionInspection */
    $queueApi->addToQueue($batchModel);
}
// testAddToQueue();

function testGetNextQueueItem() {
    /** @noinspection PhpUnhandledExceptionInspection */
    $queueApi = Di::get(QueueApi::class);

    $item = $queueApi->getNextQueueItem();

    var_dump($item);
}
// testGetNextQueueItem();

function testMarkAsStoppedDueToError() {
    /** @noinspection PhpUnhandledExceptionInspection */
    $queueApi = Di::get(QueueApi::class);

    $queueApi->markAsStoppedDueToError($queueApi->getNextQueueItem());
}
// testMarkAsStoppedDueToError();

function testMarkItemAsRun() {
    /** @noinspection PhpUnhandledExceptionInspection */
    $queueApi = Di::get(QueueApi::class);

    $queueApi->markItemAsRun($queueApi->getNextQueueItem());
}
// testMarkItemAsRun();
