/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const DocletCollection = require( './doclet-collection' );

/**
 * Collection of DocletCollections as <String, DocletCollection> pairs. Also stores all doclets in an array.
 */
class DataCollection {
	/**
	 * Creates collection of DocletCollections.
	 */
	constructor() {
		this._collections = {};
		this._allData = [];
	}

	/**
	 * Adds doclet to collection and inner DocletCollection.
	 *
	 * @param {String} category
	 * @param {Doclet} doclet
	 * @param {String} innerCategory
	 */
	add( category, doclet, innerCategory = 'default' ) {
		if ( !this._collections[ category ] ) {
			this._collections[ category ] = new DocletCollection();
		}

		this._collections[ category ].add( innerCategory, doclet );
		this._allData.push( doclet );
	}

	/**
	 * Returns DocletCollection by category.
	 *
	 * @param {String} category
	 * @returns {DocletCollection}
	 */
	get( category ) {
		return this._collections[ category ] || new DocletCollection();
	}

	/**
	 * Returns all doclets.
	 *
	 * @returns {Doclet[]}
	 */
	getAll() {
		return this._allData;
	}
}

module.exports = DataCollection;
