"use strict";
/*
 * @adonisjs/events
 *
 * (c) AdonisJS
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.FakeEmitter = void 0;
/**
 * Fake emitter to be used for finding and asserting
 * faked events
 */
class FakeEmitter {
    constructor() {
        this.events = [];
    }
    /**
     * Get all the emitted events
     */
    all() {
        return this.events;
    }
    /**
     * Returns the size of captured events
     */
    size() {
        return this.events.length;
    }
    /**
     * Find if the event has emitted
     */
    exists(eventOrCallback) {
        return !!this.find(eventOrCallback);
    }
    /**
     * Get selected events
     */
    filter(eventOrCallback) {
        if (typeof eventOrCallback === 'function') {
            return this.events.filter(eventOrCallback);
        }
        return this.events.filter((event) => event.name === eventOrCallback);
    }
    /**
     * Find a specific event
     */
    find(eventOrCallback) {
        if (typeof eventOrCallback === 'function') {
            return this.events.find(eventOrCallback);
        }
        return this.events.find((event) => event.name === eventOrCallback);
    }
    restore() {
        this.events = [];
    }
}
exports.FakeEmitter = FakeEmitter;
