//==============================================================================
// The Society of Actuaries (SOA) makes this computer model and its computer
// code available to its members for educational purposes. The model and its
// code may be modified and redistributed without prior authorization from the
// SOA. The SOA distributes this computer model and its computer code in the
// hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.
//==============================================================================

package implementation;
import agents.Environment;
import repast.simphony.context.Context;
import repast.simphony.context.DefaultContext;
import repast.simphony.context.space.continuous.ContinuousSpaceFactory;
import repast.simphony.context.space.continuous.ContinuousSpaceFactoryFinder;
import repast.simphony.context.space.gis.GeographyFactoryFinder;
import repast.simphony.context.space.graph.NetworkBuilder;
import repast.simphony.dataLoader.ContextBuilder;
import repast.simphony.space.continuous.ContinuousSpace;
import repast.simphony.space.continuous.SimpleCartesianAdder;
import repast.simphony.space.gis.Geography;
import repast.simphony.space.gis.GeographyParameters;
import resources.Constants;

//==============================================================================
//Import statements
//------------------------------------------------------------------------------

public class SimulationContext extends DefaultContext<Object> implements ContextBuilder<Object>
{

    //==============================================================================
    // Method:  build
    // Note:    This class is where the simulation starts.
    //          Its constructor overrides a Repast method. 
    //------------------------------------------------------------------------------    

     @Override
     public Context<Object> build(Context<Object> pContext)
     {
         pContext.setId(Constants.CONTEXT_ID);
         
         // Create the "community" continuous space projection and add it to the context
         ContinuousSpaceFactory spaceFactory = ContinuousSpaceFactoryFinder
                 .createContinuousSpaceFactory(null);
         
         ContinuousSpace<Object> communitySpace = spaceFactory.createContinuousSpace
         (
             Constants.COMMUNITY_SPACE_ID,
             pContext,
             new SimpleCartesianAdder<Object>(),
             new repast.simphony.space.continuous.WrapAroundBorders(),
             Constants.COMMUNITY_SPACE_SIZE,
             Constants.COMMUNITY_SPACE_SIZE
         );//end .createContinuousSpace()         


         // Create a Person-Health Insurance Company A network and add it to the context
         NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>("Person-Insurer network", pContext, false);
         netBuilder.buildNetwork();

         // Create the "State" geography projection and add it to the context.
        GeographyParameters<Object> geographyParameters = new GeographyParameters<Object>();
        Geography<Object> geography = GeographyFactoryFinder.createGeographyFactory(null).createGeography("State", pContext, geographyParameters);

         //Establish the Environment, and add it to the context.
         Environment environment;
         environment = null;
         
         environment = new Environment(communitySpace, geography, pContext);

         pContext.add(environment);

         return pContext;

     }//end build()
     
}//end SimulationContexts class
