package com.github.aureliano.evtbridge.app.command;

import com.github.aureliano.evtbridge.app.ErrorCode;
import com.github.aureliano.evtbridge.app.helper.ConfigurationSchemaHelper;
import com.github.aureliano.evtbridge.common.exception.EventBridgeException;
import com.github.aureliano.evtbridge.common.helper.StringHelper;
import com.github.aureliano.evtbridge.core.SchemaTypes;
import com.github.aureliano.evtbridge.core.doc.DocumentationSourceTypes;

public class SchemaCommand implements ICommand {

	private String type;
	private String name;
	private String format;
	
	public SchemaCommand() {
		this.format = "json";
	}

	public ErrorCode execute() {
		ErrorCode errorCode = this.validate();
		if (errorCode == null) {
			System.out.println(ConfigurationSchemaHelper.fetchSchema(this.type, this.name, this.format));
		}
		
		return errorCode;
	}
	
	private ErrorCode validate() {
		if (StringHelper.isEmpty(this.type)) {
			throw new EventBridgeException("Parameter (-t --type) is required.");
		}
		
		try {
			SchemaTypes.valueOf(this.type.toUpperCase());
		} catch (IllegalArgumentException ex) {
			System.err.println("Invalid schema type parameter [" + this.type + "]");
			return ErrorCode.SCHEMA_PARAM_ERROR;
		}
		
		try {
			DocumentationSourceTypes.valueOf(this.format.toUpperCase());
		} catch (IllegalArgumentException ex) {
			System.err.println("Invalid schema format parameter [" + this.format+ "]");
			return ErrorCode.SCHEMA_PARAM_ERROR;
		}
		
		return null;
	}

	public String id() {
		return Commands.SCHEMA.getId();
	}

	public String getType() {
		return type;
	}

	public SchemaCommand withType(String type) {
		this.type = type;
		return this;
	}

	public String getName() {
		return name;
	}

	public SchemaCommand withName(String name) {
		this.name = name;
		return this;
	}

	public String getFormat() {
		return format;
	}

	public SchemaCommand withFormat(String format) {
		this.format = format;
		return this;
	}
}
@@ -498,16 +498,72 @@
 mand %7B%0A%0A
+%09private static final String DEFAULT_FORMAT = %22json%22;%0A%09%0A
 %09private
@@ -653,34 +653,8 @@
 () %7B
-%0A%09%09this.format = %22json%22;%0A%09
 %7D%0A%0A%09
@@ -682,16 +682,99 @@
 ute() %7B%0A
+%09%09if (StringHelper.isEmpty(this.format)) %7B%0A%09%09%09this.format = DEFAULT_FORMAT;%0A%09%09%7D%0A%09%09%0A
 %09%09ErrorC

Handle error on schema command and apply validations.