package com.capgemini.reports.builder;

import com.capgemini.reports.database.javabean.enumeration.ReportCriteriaEnum;
import com.capgemini.reports.definition.r22report.ExecutionR22;
import com.capgemini.reports.exceptions.InsufficientParametersException;
import com.google.common.base.Joiner;

import java.util.Map;

/** Builds a R22 Report from Part Id & rev. */
public class R22Builder implements ReportBuilder {

    @Override
    public ExecutionR22 build(Map<ReportCriteriaEnum, String> data) throws InsufficientParametersException {
        // Get the request raw data
        String partId = data.get(ReportCriteriaEnum.PART_ID);
        String partRevision = data.get(ReportCriteriaEnum.PART_REVISION);

        // Check presence of all required args
        if (partId == null || partRevision == null) {
            String dataStr = Joiner.on('|').withKeyValueSeparator("=").useForNull("null").join(data);
            throw new InsufficientParametersException("Missing parameter for R22 launch. Obtained: " + dataStr);
        }

        // Build the report
        return new ExecutionR22(partId, partRevision);
    }

}
