package com.capgemini.reports.definition.r15r16r17reports.r15r17reports.r17report;

import com.capgemini.framework.common.SettingsHelper;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.reports.JasperTemplate;
import com.capgemini.reports.ReportEnum;
import com.capgemini.reports.ReportLaunchTypeEnum;
import com.capgemini.reports.builder.R17Builder;
import com.capgemini.reports.builder.ReportBuilder;
import com.capgemini.reports.definition.r15r16r17reports.r15r17reports.AbstractExecutionR15R17;
import com.capgemini.reports.execution.AbstractExecutionReport;
import com.capgemini.reports.execution.IDataReportPreparator;
import com.capgemini.reports.printing.Printer.PrintFormat;
import com.capgemini.reports.reports.parameters.IChecker;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * This class controls the execution of a R17 report.
 */
@Getter
@EqualsAndHashCode(callSuper = true)
public class ExecutionR17 extends AbstractExecutionR15R17<ExecutionR17> {
    private static final long serialVersionUID = -7971226717525563715L;

    private static final String FILE_SEPARATOR = "_";

    // Policies
    private static final PolicyLocation R17_POLICY_XML_FULL = PolicyLocation.make("R17_policy_full", "/xml/policies/r17report/R17_policy_full.xml");
    private static final PolicyLocation R17_POLICY_XML_LIGHT = PolicyLocation.make("R17_policy_light", "/xml/policies/r17report/R17_policy_light.xml");

    // Priority parameter
    private static final int REPORT_PRIORITY = SettingsHelper.getPriority(ReportEnum.REPORT_R17);

    // Revision rule parameter
    private static final String REPORT_REVISION_RULE = SettingsHelper.getPropertyWithDefaultValue("common.bom.revisionRule.REPORT_R17", DEFAULT_REVISION_RULE);

    // Launch type parameter
    private static final ReportLaunchTypeEnum REPORT_LAUNCH_TYPE = ReportLaunchTypeEnum.getReportLaunchType("common.launch.launchType.REPORT_R17");

    /**
     * Constructor.
     *
     * @param partId       {@link String} - the ID of the Part
     * @param partRevision {@link String} - the Revision of the Part
     * @param langue       {@link String} - the language selected by the user
     */
    public ExecutionR17(final String partId, final String partRevision, final String langue) {
        super(partId, partRevision, langue, REPORT_PRIORITY, REPORT_REVISION_RULE, REPORT_LAUNCH_TYPE);
    }

    @Override
    public String getTemplateLocation() {
        return JasperTemplate.TEMPLATE_R17.getFilepath();
    }

    @Override
    public PolicyLocation getPropertyPolicyForLongChecks() {
        return R17_POLICY_XML_LIGHT;
    }

    @Override
    public PolicyLocation getFullPolicy() {
        return R17_POLICY_XML_FULL;
    }

    @Override
    public List<IChecker> getLongChecks() {
        return new ArrayList<>();
    }

    @Override
    public ReportEnum getReportIdentifier() {
        return ReportEnum.REPORT_R17;
    }

    @Override
    public String getSpecifiedFileName() {
        StringBuilder filename =
                new StringBuilder(itemId).append(FILE_SEPARATOR).append(itemRevision).append(FILE_SEPARATOR).append("ListeDocRefart");
        if (!isFrench()) {
            filename.append("_ENG");
        }
        return filename.toString();
    }

    @Override
    public PrintFormat getPrintingFormat() {
        return PrintFormat.PDF;
    }

    @Override
    public IDataReportPreparator<ExecutionR17> getDataPreparator() {
        return new DataReportPreparatorR17();
    }

    @Override
    public AbstractExecutionReport<?, ?> cloneTemplateToExecution() {
        return new ExecutionR17(itemId, itemRevision, frenchInput);
    }

    @Override
    public Class<? extends ReportBuilder> getReportBuilderClass() {
        return R17Builder.class;
    }
}
