/*
 * ROMAN DIGITAL - Autor: Américo Patetta
 */
package com.teltonikaServer.network;

import com.teltonikaServer.persistence.Command;
import java.time.Instant;
import java.util.ArrayList;

/**
 *
 * @author pc
 */
public class UnitCommandList {
    
    protected String imei;
    protected ArrayList<Command> commands;

    
    
    public Command getFirstPendingCommand(){
        Command firstPendingCommand = null;
        for(Command command : commands){
            if(command.getRetriesLeft()>0 && (command.getSentTimestamp() + command.getGap()) < Instant.now().getEpochSecond()){
                firstPendingCommand = command;
                break;
            }
        }
        return firstPendingCommand;
    }
    
    public String getImei() {
        return imei;
    }

    public ArrayList<Command> getCommands() {
        return commands;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public void setCommands(ArrayList<Command> commands) {
        this.commands = commands;
    }
    
    
}
