<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Core\Contract\DeferrerEvent\Trait;

defined( 'ABSPATH' ) || exit;

trait HasDeferredEvents
{
    protected array $deferredEvents = [];

    /**
     * Add a deferred event to the stack.
     */
    public function deferEvent(object $event): void
    {
        $this->deferredEvents[] = $event;
    }

    /**
     * Obtain all deferred events.
     */
    public function releaseDeferredEvents(): array
    {
        $events               = $this->deferredEvents;
        $this->deferredEvents = [];
        return $events;
    }
}
