package com.capgemini.reports.printing;

import com.capgemini.reports.exceptions.ReportPrintException;
import com.capgemini.reports.execution.AbstractExecutionReport;

import java.io.InputStream;

/**
 * This class helper will allow to use the method which will set up the parameters for the printing.
 *
 */
public final class PrintReportHelper {

    private PrintReportHelper() {

    }

    /**
     * Sets up basic printing parameters.
     * <ul>
     * <li>Main report Template</li>
     * <li>Output folder</li>
     * <li>File name</li>
     * <li>Report title</li>
     * </ul>
     *
     * @param template the report template. NOTE: the {@link InputStream} is consumed in this method, but it is the resposibility of the caller to perform the {@link InputStream#close() close()} operation.
     * @param outputFolder folder where the file will be saved
     * @param outputFileName name of the file as it will be saved on disc
     * @param aAbstractExecutionReport will provide all informations for the report which is executing
     * @return the PrintParameters configured
     * @throws ReportPrintException if the template could not be understood by the printer.
     */
    public static PrintParameters setupPrintParameters(final InputStream template, final String outputFolder, final String outputFileName,
            final AbstractExecutionReport<?, ?> aAbstractExecutionReport) throws ReportPrintException {
        PrintParameters printParameters =
                PrintParameters.createMainReport(aAbstractExecutionReport.getPrintingFormat(), outputFileName, outputFolder, template);
        printParameters.setReportTitle(aAbstractExecutionReport.getReportIdentifier().getReportTitle());
        return printParameters;
    }

    /**
     * Sets up basic printing parameters.
     * <ul>
     * <li>Main report Template</li>
     * <li>Output folder</li>
     * <li>File name</li>
     * <li>Report title</li>
     * </ul>
     *
     * @param template the template (a {@link String} containing the actual .jrxml content)
     * @param outputFolder the folder where the file will be saved
     * @param outputFileName the file name
     * @param aAbstractExecutionReport will provide all informations for the report which is executing
     * @return the PrintParameters configured
     * @throws ReportPrintException if unable to create the report template
     */
    public static PrintParameters setupPrintParameters(final String template, final String outputFolder, final String outputFileName,
            final AbstractExecutionReport<?, ?> aAbstractExecutionReport) throws ReportPrintException {
        PrintParameters printParameters =
                PrintParameters.createMainReport(aAbstractExecutionReport.getPrintingFormat(), outputFileName, outputFolder, template);
        printParameters.setReportTitle(aAbstractExecutionReport.getReportIdentifier().getReportTitle());
        return printParameters;
    }
}
