/* ========================================================================
 * PlantUML : a free UML diagram generator
 * ========================================================================
 *
 * (C) Copyright 2009-2024, Arnaud Roques
 *
 * Project Info:  https://plantuml.com
 * 
 * If you like this project or if you find it useful, you can support us at:
 * 
 * https://plantuml.com/patreon (only 1$ per month!)
 * https://plantuml.com/paypal
 * 
 * This file is part of PlantUML.
 *
 * PlantUML is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PlantUML distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 *
 * Original Author:  Arnaud Roques
 *
 *
 */
package net.sourceforge.plantuml.api.v2;

import java.io.IOException;
import java.util.Optional;

import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.klimt.awt.PortableImage;

/**
 * Provides an interface to retrieve the results of a diagram processing
 * operation. This interface allows for obtaining either a {@link Diagram}
 * object if the operation was successful, or an error message if the operation
 * failed, along with the line number where the error occurred.
 */
public interface DiagramReturn {

	/**
	 * Retrieves the {@link Diagram} generated by the diagram processing operation.
	 * 
	 * @return the generated {@link Diagram}, or {@code null} if there was an error
	 *         during the diagram generation process, implying that no valid diagram
	 *         could be created.
	 */
	public Diagram getDiagram();

	/**
	 * Retrieves the error message associated with the diagram processing operation.
	 * 
	 * @return the error message if an error occurred, or {@code null} if the
	 *         operation completed successfully and a valid diagram was produced.
	 */
	public String error();

	/**
	 * Retrieves the line number where an error occurred during the diagram
	 * processing operation. This can help in debugging the source of the error in
	 * the input provided.
	 *
	 * @return an {@link Optional} containing the line number of the error if an
	 *         error occurred; otherwise, an empty {@link Optional} if the operation
	 *         completed successfully without errors.
	 */
	public Optional<Integer> getErrorLine();

	/**
	 * Converts the generated diagram to an image representation. This can be useful for displaying
	 * the diagram in graphical user interfaces or for saving it as a file.
	 *
	 * @return a {@link PortableImage} representing the diagram.
	 * @throws IOException if there is an error during the image generation process, such as an issue
	 *         writing to a file or generating the image from the diagram.
	 */
	public PortableImage asImage() throws IOException;

	/**
	 * Retrieves the root cause of the error occurred during the diagram processing operation.
	 * This method can be particularly useful for obtaining detailed information about exceptions
	 * that were caught during the processing of the diagram.
	 *
	 * @return a {@link Throwable} object representing the root cause of the error, or {@code null}
	 *         if the operation completed successfully without any exceptions.
	 */
	public Throwable getRootCause();

}
