package com.capgemini.framework.teamcenter.object.runtime;

import com.capgemini.framework.teamcenter.ServiceDataHelper;
import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.exceptions.KurtException;
import com.teamcenter.services.strong.cad._2007_01.StructureManagement.CreateBOMWindowsOutput;
import com.teamcenter.services.strong.cad._2007_01.StructureManagement.CreateBOMWindowsResponse;

public class TcBomWindowFactory {
    private final TcBomWindowConfiguration bomWindowConfiguration;
    private final TcSession session;

    public TcBomWindowFactory(final TcSession session, final TcBomWindowConfiguration bomWindowConfiguration) {
        this.session = session;
        this.bomWindowConfiguration = bomWindowConfiguration;
    }

    public TcBomWindow create() throws KurtException {
        CreateBOMWindowsResponse createBOMWindowsResponse = session.getStructureManagementService().createBOMWindows2(bomWindowConfiguration.toTcInfo());
        if (ServiceDataHelper.hasErrors(createBOMWindowsResponse.serviceData)) {
            ServiceDataHelper.displayErrors(createBOMWindowsResponse.serviceData);
            throw new KurtException("Error while creating bom window.");
        }
        CreateBOMWindowsOutput bomWindowsOutput = createBOMWindowsResponse.output[0];
        return new TcBomWindow(session, bomWindowsOutput.bomWindow);
    }
}
