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

'use strict';

const AbstractParser = require( './abstractparser' );

module.exports = class EventParser extends AbstractParser {
	/**
	 * @param {BaseReflection} item
	 * @returns {Boolean}
	 */
	canParse( item ) {
		return item.isCKEditor5Event === true;
	}

	/**
	 * @param {CKEditor5EventReflection} item
	 * @param {String} parentName
	 * @returns {Object}
	 */
	parse( item, parentName ) {
		// TypeDoc adds the "event:" prefix to the event name to make sure the name is unique in the scope of its parent.
		// Here, in the parser, we do not need it anymore.
		item.name = item.name.replace( 'event:', '' );

		return {
			// Needed for post-processing once all project reflections are converted.
			_signature: [ {}, item ],

			name: item.name,
			memberof: parentName,
			longname: this.getLongName( item, parentName ),

			scope: this.getScope( item ),
			kind: this.getKind( item ),
			extraId: this.getExtraId( item ),
			description: this.getComment( item ),
			file: this.getFile( item ),
			skipSource: this.shouldSkipSource( item ),
			deprecated: this.isDeprecated( item ),
			inherited: !!item.inheritedFrom,
			see: this.getRelated( item, parentName ),

			// These properties will be filled in the post-processing phase.
			params: null
		};
	}
};
