package communication.messages;

import common.Motor;
import elevator.Elevator.ElevatorAction;
import floor.input.InputEvent;

/**
 * This class simulates a request when scheduler commanding
 * elevator
 * ID - ID of elevator
 * Action - open, moving UP, moving DOWN, update current floor, destination floor, initialize numfloors, turn off lamp
 * data - will be 0 for  OPEN, UP, DOWN
 */
public class ElevatorActionMessage implements Message {
	private static final long serialVersionUID = 5062262196030046676L;

	private final int elevatorId;
	private final ElevatorAction action;
	private final int requestedFloor; // will be ignored if the operation does not involves floors
	// used for when we first request an elevator, there is some information we need to pass along that is in the input event
	private final InputEvent inputEvent;
	private final Motor motor; // for ARRIVE_AND_CONTINUE only

	/**
	 * Used when we receive an input event from the floor requesting an elevator. We need to pass
	 * the input event so that we can save some states in the event in the elevator system
	 *
	 * @param elevatorId
	 * @param action
	 * @param requestedFloor
	 * @param inputEvent
	 */
	public ElevatorActionMessage(int elevatorId, ElevatorAction action, int requestedFloor, InputEvent inputEvent, Motor motor) {
		this.elevatorId = elevatorId;
		this.action = action;
		this.requestedFloor = requestedFloor;
		this.inputEvent = inputEvent;
		this.motor = motor;
	}

	/**
	 * Used anytime we need to send an action to the elevator
	 *
	 * @param elevatorId
	 * @param action
	 * @param requestedFloor
	 */
	public ElevatorActionMessage(int elevatorId, ElevatorAction action, int requestedFloor) {
		this(elevatorId, action, requestedFloor, null, null);
	}

	public int getElevatorId() {
		return elevatorId;
	}

	public ElevatorAction getAction() {
		return action;
	}

	public int getRequestedFloor() {
		return requestedFloor;
	}

	public InputEvent getInputEvent() {
		return inputEvent;
	}

	public Motor getMotorDirection() {
		return motor;
	}

	@Override
	public String toString() {
		return "ElevatorActionMessage [elevatorId=" + elevatorId + ", action=" + action + ", requestedFloor="
				+ requestedFloor + "]";
	}
}
