package com.capgemini.reports.builder;

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

import java.util.Map;

/** Reconstructs a R03 report from Part Id and rev. */
public class R03Builder implements ReportBuilder {

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

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

        // Build the report
        return new ExecutionR03(partId, partRev);
    }

}
