/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
// Copyright (C) 2017-2018 German Aerospace Center (DLR) and others.
// TraaS module
// Copyright (C) 2016-2017 Dresden University of Technology
// This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v20.html
// SPDX-License-Identifier: EPL-2.0
/****************************************************************************/
/// @file    ContextSubscription.java
/// @author  Mario Krumnow
/// @author  Evamarie Wiessner
/// @date    2016
/// @version $Id$
///
//
/****************************************************************************/
package de.tudresden.sumo.subscription;

import java.util.LinkedList;

import de.tudresden.sumo.config.Constants;
import it.polito.appeal.traci.protocol.Command;

public class ContextSubscription implements Subscription  {

	public SubscriptionContext context;
	public double start;
	public double stop;
	public String objectID;
	public SumoDomain contextDomain;
	public double contextRange;
	public LinkedList<Integer> commands;
	
	public ContextSubscription(){
		
		//demo
		this.context = SubscriptionContext.lane;
		this.start = 0;
		this.stop = 100000 * 60;
		this.objectID = "gneE0_0";
		this.contextDomain = SumoDomain.vehicles;
		this.contextRange = 100;
		
		this.commands = new LinkedList<Integer>();
		this.commands.add(Constants.VAR_POSITION);
		this.commands.add(Constants.VAR_SPEED);
		
	}
	
	public ContextSubscription(SubscriptionContext context, double start, double stop, String objectID, SumoDomain contextDomain, double contextRange){
		
		this.context = context;
		this.start = start;
		this.stop = stop;
		this.objectID = objectID;
		this.contextDomain = contextDomain;
		this.contextRange = contextRange;
		this.commands = new LinkedList<Integer>();
	}
	
	public void addCommand(int cmd){this.commands.add(cmd);}
	
	public Command getCommand() {
		
		Command cmd = new Command(this.context.id);
		cmd.content().writeDouble(this.start);
		cmd.content().writeDouble(this.stop);
		cmd.content().writeStringASCII(this.objectID);
		cmd.content().writeUnsignedByte(this.contextDomain.id);
		cmd.content().writeDouble(this.contextRange);
		cmd.content().writeUnsignedByte(this.commands.size());
		for(Integer ix : this.commands){cmd.content().writeUnsignedByte(ix);}
		
		return cmd;
	}
	
}