package at.oefai.aaa.agent.jam;

import at.oefai.aaa.agent.jam.types.Binding;

/**
 * Represents an agent's goals.
 * @author Marc Huber
 * @author Jaeho Lee
 */
public class DataDrivenGoal extends AbstractGoal {
    private final Relation concludeRelation; // The Relation (if any) responsible for the
    // goal being created for data-driven behavior

    /** Constructor with the goal specification, conclude relation, parent goal, and intention structure as parameters. */
    public DataDrivenGoal(final Relation pConcludeRelation, final IntentionStructure is) {
        super(is);
        this.concludeRelation = pConcludeRelation;
    }

    // Member functions

    public final Relation getConcludeRelation() {
        return this.concludeRelation;
    }


    /** Find matches between bound and unbound variables. */
    public final boolean matchRelation(final Relation dstRelation, final Binding dstBinding) {
        return false;
    }


    /** Format output to the given stream so that it can be in-line with other output. */
    public final String formattedString() {
        StringBuffer sb = new StringBuffer();
        sb.append("DataDrivenGoal: ");
        sb.append("  concludeRel: ");
        if (this.concludeRelation != null) {
            sb.append(this.concludeRelation.formattedString(getGoalBinding()) + "\n");
        } else {
            sb.append("null");
        }
        sb.append(" || Utility: " + this.getIntendedUtility() + "\n");
        sb.append(", New?: " + isNew());
        sb.append(", Status: " + getStatus());
        sb.append(", Subgoal: " + ((getSubgoal() != null) ? getSubgoal().getName() : "NONE"));
        sb.append(", Intention: " + getIntention());
        sb.append(", RuntimeState: " + getRuntimeState());
        return sb.toString();
    }

    public final String toString() {
        StringBuffer sb = new StringBuffer();
        if (isNew()) {
            sb.append("New ");
        }
        sb.append("DataDrivenGoal ");
        sb.append("|Utility:" + this.getFixedPointIntendedUtility() + "| ");
        if (this.concludeRelation != null) {
            sb.append(this.concludeRelation.formattedString(getGoalBinding()));
        } else {
            sb.append("null");
        }
        sb.append(" | " + getStatus());
        APLElement ae = getIntention();
        if (ae != null && ae.getPlan() != null) {
            sb.append(", Plan: " + ae.getPlan().getName());
        } else {
            sb.append(", no Intention");
        }
        return sb.toString();
    }
}
