<commit_before>package com.github.aureliano.evtbridge.core.doc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.aureliano.evtbridge.common.exception.EventBridgeException;
import com.github.aureliano.evtbridge.core.SchemaTypes;
import com.github.aureliano.evtbridge.core.config.EventCollectorConfiguration;
import com.github.aureliano.evtbridge.core.config.IConfiguration;
import com.github.aureliano.evtbridge.core.config.InputConfigTypes;
import com.github.aureliano.evtbridge.core.config.OutputConfigTypes;
import com.github.aureliano.evtbridge.core.schedule.SchedulerTypes;

public class MapSchemaBuilder extends SchemaBuilder<Map<String, Object>> {

	public MapSchemaBuilder() {}

	@Override
	public Map<String, Object> build(SchemaTypes schemaType) {
		switch (schemaType) {
		case ROOT:
			return this.buildRootSchema();
		case SCHEDULER:
			return this.buildSchedulerSchema();
		case INPUT:
			return this.buildInputSchema();
		case OUTPUT:
			return this.buildOutputSchema();
		default:
			throw new EventBridgeException("Unsupported schema type '" + schemaType + "'");
		}
	}
	
	@Override
	public Map<String, Object> build(SchedulerTypes schedulerType) {
		return null;
	}

	private Map<String, Object> buildOutputSchema() {
		return this.buildAggregationSchema("Output configuration.", OutputConfigTypes.values());
	}

	private Map<String, Object> buildInputSchema() {
		return this.buildAggregationSchema("Input configuration.", InputConfigTypes.values());
	}

	private Map<String, Object> buildSchedulerSchema() {
		return this.buildAggregationSchema("Scheduling execution configuration.", SchedulerTypes.values());
	}

	private Map<String, Object> buildRootSchema() {
		if (super.schema != null) {
			super.schema.clear();
		}
		
		Class<? extends IConfiguration> configuration = EventCollectorConfiguration.class;
		super.configureSchemaHeader(configuration);
		super.configureSchemaProperties(configuration);
		
		return super.schema;
	}
	
	private Map<String, Object> buildAggregationSchema(String title, Object[] values) {
		if (super.schema != null) {<commit_msg>Code refactoring: make build schema method generic.<commit_after>package com.github.aureliano.evtbridge.core.doc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.aureliano.evtbridge.common.exception.EventBridgeException;
import com.github.aureliano.evtbridge.core.SchemaTypes;
import com.github.aureliano.evtbridge.core.config.EventCollectorConfiguration;
import com.github.aureliano.evtbridge.core.config.IConfiguration;
import com.github.aureliano.evtbridge.core.config.InputConfigTypes;
import com.github.aureliano.evtbridge.core.config.OutputConfigTypes;
import com.github.aureliano.evtbridge.core.schedule.SchedulerTypes;

public class MapSchemaBuilder extends SchemaBuilder<Map<String, Object>> {

	public MapSchemaBuilder() {}

	@Override
	public Map<String, Object> build(SchemaTypes schemaType) {
		switch (schemaType) {
		case ROOT:
			return this.buildSchema(EventCollectorConfiguration.class);
		case SCHEDULER:
			return this.buildSchedulerSchema();
		case INPUT:
			return this.buildInputSchema();
		case OUTPUT:
			return this.buildOutputSchema();
		default:
			throw new EventBridgeException("Unsupported schema type '" + schemaType + "'");
		}
	}
	
	@Override
	public Map<String, Object> build(SchedulerTypes schedulerType) {
		switch (schedulerType) {
		case EXECUTE_PERIODICALLY:
			
			break;

		default:
			break;
		}
		
		return null;
	}

	private Map<String, Object> buildOutputSchema() {
		return this.buildAggregationSchema("Output configuration.", OutputConfigTypes.values());
	}

	private Map<String, Object> buildInputSchema() {
		return this.buildAggregationSchema("Input configuration.", InputConfigTypes.values());
	}

	private Map<String, Object> buildSchedulerSchema() {
		return this.buildAggregationSchema("Scheduling execution configuration.", SchedulerTypes.values());
	}

	private Map<String, Object> buildSchema(Class<? extends IConfiguration> configuration) {
		if (super.schema != null) {
			super.schema.clear();
		}
		
		super.configureSchemaHeader(configuration);
		super.configureSchemaProperties(configuration);
		
		return super.schema;
	}
	
	private Map<String, Object> buildAggregationSchema(String title, Object[] values) {
		if (super.schema != null) {
{'fraction_non_alphanumeric': 0.10845006778129236, 'fraction_numerical': 0.0, 'mean_word_length': 5.707575757575758, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '144867', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1277, 'n_words': 257}