/*
 * © 2013-2019 by Zappware. 
 * All Rights Reserved. No part of this application or any of its contents may be reproduced, 
 * copied, modified or adapted, without the prior written consent of Zappware.
 *
 * Website: http://www.zappware.com
 * E-Mail: info@zappware.com
 */
package com.zappware.graphlperftest.datafetchers;

import com.zappware.graphlperftest.ProcessingSettings;
import com.zappware.graphlperftest.model.ModelGenerator;
import com.zappware.graphlperftest.model.TypeTwo;
import com.zappware.graphlperftest.processing.CPULoadGenerator;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;

/**
 * Data fetcher for the second query
 */
public class QueryTwoDataFetcher implements DataFetcher<TypeTwo>
{
	/** The source of the model objects. */
	private ModelGenerator modelGenerator;
	/** The generator of CPU load to simulate processing. */
	private CPULoadGenerator loadGenerator;

	/**
	 * Constructor.
	 * @param modelGenerator
	 */
	public QueryTwoDataFetcher(ModelGenerator modelGenerator, CPULoadGenerator loadGenerator)
	{
		this.modelGenerator = modelGenerator;
		this.loadGenerator = loadGenerator;
	}
	
	/**
	 * @see graphql.schema.DataFetcher#get(graphql.schema.DataFetchingEnvironment)
	 */
	@Override
	public TypeTwo get(DataFetchingEnvironment environment) throws Exception
	{
		loadGenerator.generateLoad();
		return ProcessingSettings.returnFromDataFetcher ? modelGenerator.getTypeTwo() : null;
	}
}