package com.capgemini.reports.printing;

import com.capgemini.framework.teamcenter.exceptions.KurtException;
import com.capgemini.reports.exceptions.ReportPrintException;

import java.io.File;

/**
 * This class can print a report using a certain API (JASPER, BURT...) on a {@link PrintParameters}.
 */
public class Printer {

    private final AvailablePrinter availablePrinter;

    /**
     * Construit un Printer en specifiant le plugin a utiliser (JASPER, BURT...).
     *
     * @param printer le plugin a utiliser pour imprimer
     */
    public Printer(final AvailablePrinter printer) {
        this.availablePrinter = printer;
    }

    /**
     * Effectue l'impression proprement dite.
     *
     * @param params les parametres d'impression
     * @return a {@link File} referencing the produced document
     * @throws ReportPrintException if a Jasper exception was thrown
     */
    public File print(final PrintParameters params) throws KurtException {
        switch (availablePrinter) {
            case JASPER:
                return params.jasperPrint();
            case ZIP:
                return params.createZip();
            default:
                return params.consolePrint();
        }
    }

    /**
     * All sorts of available output formats.
     */
    public enum PrintFormat {
        PDF,
        XLSX,
        CSV,
        ZIP
    }

    /**
     * All sorts of available output formats.
     */
    public enum AvailablePrinter {
        JASPER,
        ZIP,
        TEST
    }
}
