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

'use strict';

const TypedocConverter = require( './typedoc/typedocconverter' );
const ModuleParser = require( './typedoc/moduleparser' );
const ClassParser = require( './typedoc/classparser' );
const AccessorParser = require( './typedoc/accessorparser' );
const InterfaceParser = require( './typedoc/interfaceparser' );
const ConstantParser = require( './typedoc/constantparser' );
const TypeParser = require( './typedoc/typeparser' );
const FunctionParser = require( './typedoc/functionparser' );
const PropertyParser = require( './typedoc/propertyparser' );
const ComputedPropertyParser = require( './typedoc/computedpropertyparser' );
const MethodParser = require( './typedoc/methodparser' );
const ConstructorParser = require( './typedoc/constructorparser' );
const ErrorParser = require( './typedoc/errorparser' );
const EventParser = require( './typedoc/eventparser' );
const ReferenceParser = require( './typedoc/referenceparser' );

module.exports = data => {
	const projectReflection = JSON.parse( data );

	if ( !projectReflection.children ) {
		console.warn( 'No doclets found in passed data.' );

		return [];
	}

	const typedoc = new TypedocConverter( [
		// Top level. All things belong to a module.
		ModuleParser,

		// Children of a module.
		ClassParser,
		InterfaceParser,
		FunctionParser,
		ConstantParser,
		TypeParser,
		ErrorParser,

		// Children of an interface or a class.
		ConstructorParser,
		MethodParser,
		AccessorParser,
		PropertyParser,
		ComputedPropertyParser,

		// Events of an interface or a class.
		EventParser,

		// Helper for processing a package entry point.
		ReferenceParser
	] );

	return typedoc.convertToJsDoc( projectReflection );
};
