package ua.be.wee.model;

import java.util.UUID;

import ua.be.wee.model.nodes.Node;
import ua.be.wee.model.pm.PM;
import ua.be.wee.model.pt.PT;

public class Token {
    private final String id;
    private Node currentNode;
    private final PT processTrace;
    private final PM processModel;
    private final String branchId;
    private final String invokingActivityName;
    private boolean active;

    public Token(Node currentNode, PT processTrace, String branchId, String invokingActivityName) {
        this.id = UUID.randomUUID().toString();
        this.currentNode = currentNode;
        this.processTrace = processTrace;
        this.processModel = processTrace.getPmEnacted();
        this.branchId = branchId;
        this.invokingActivityName = invokingActivityName;
        this.active = true;
    }

    public String getId() {
        return id;
    }

    public Node getCurrentNode() {
        return currentNode;
    }

    public void setCurrentNode(Node currentNode) {
        this.currentNode = currentNode;
    }

    public PT getProcessTrace() {
        return processTrace;
    }

    public PM getProcessModel() {
        return processModel;
    }

    public String getBranchId() {
        return branchId;
    }

    public String getInvokingActivityName() {
        return invokingActivityName;
    }

    public boolean isActive() {
        return active;
    }

    public void terminate() {
        this.active = false;
    }

    @Override
    public String toString() {
        return "Token{" +
                "id='" + id + '\'' +
                ", currentNode=" + (currentNode != null ? currentNode.getIri() : "null") +
                ", processModel=" + (processModel != null ? processModel.getName() : "null") +
                ", processTrace='" + processTrace.getIri() + '\'' +
                ", branchId='" + branchId + '\'' +
                ", invokingActivityName='" + invokingActivityName + '\'' +
                ", active=" + active +
                '}';
    }
}
