package be.iminds.ilabt.jfed.rspec.model.controller;

import javax.xml.bind.annotation.*;
import java.util.Date;
import java.util.Objects;

/**
 * @author Cedric
 */
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement()
public class ExperimentCommandOutput {
    private String nodeID, nodeHostname, commandTag, command, output, error;
    private Date startTime, stopTime;

    public ExperimentCommandOutput() {
        nodeID = "";
        nodeHostname = "";
        commandTag = "";
        command = "";
        output = "";
        error = "";
        startTime = null;
        stopTime = null;
    }

    @XmlAttribute
    public String getNodeID() {
        return nodeID;
    }

    public void setNodeID(String nodeID) {
        this.nodeID = nodeID;
    }

    @XmlAttribute
    public String getNodeHostname() {
        return nodeHostname;
    }

    public void setNodeHostname(String nodeHostname) {
        this.nodeHostname = nodeHostname;
    }

    @XmlAttribute
    public String getCommandTag() {
        return commandTag;
    }

    public void setCommandTag(String commandTag) {
        this.commandTag = commandTag;
    }

    @XmlAttribute
    public String getCommand() {
        return command;
    }

    public void setCommand(String command) {
        this.command = command;
    }

    public void start() {
        startTime = new Date();
    }

    public void stop() {
        stopTime = new Date();
    }

    @XmlElement
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    @XmlElement
    public void setStopTime(Date stopTime) {
        this.stopTime = stopTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public Date getStopTime() {
        return stopTime;
    }

    public String getOutput() {
        return output;
    }

    @XmlElement
    public void setOutput(String output) {
        this.output = output;
    }

    public String getError() {
        return error;
    }

    @XmlElement
    public void setError(String error) {
        this.error = error;
    }

    public boolean hasOutput() {
        return !Objects.equals(output, "");
    }

    public boolean hasError() {
        return !Objects.equals(error, "");
    }
}
