package at.oefai.aaa.agent.jam;


/**
 * Represents an especially high or low (love and hate) preference for an object.
 * @author Stefan Rank
 */
class ObjectAppraisal extends AbstractFactAppraisal {

    // a cache of the actual preference value, although it is also in the relation:
    private float preference = 0;

    ObjectAppraisal(final float pPreferenceValue, final WorldModelRelation pRelation,
                    final Interpreter pInterpreter) {
        super(pRelation, pInterpreter);
        this.setPreference(pPreferenceValue);
        // if new post an immediate emotion goal (impulse) with high 'utility' if emotional enough
        this.postImpulse();
        this.infoProcessingEffects(pInterpreter.getWorldModel());
        this.tryToCope();
    }

    public static ObjectAppraisal newObjectAppraisal(final float pPreferenceValue, final WorldModelRelation pRelation,
            final Interpreter pInterpreter) {
        return new ObjectAppraisal(pPreferenceValue, pRelation, pInterpreter);
    }

    private void setPreference(final float pPreferenceValue) {
        this.preference = pPreferenceValue;
    }

    public void update(final float preferenceValue) {
        this.setPreference(preferenceValue);
    }

    public void infoProcessingEffects(final WorldModelTable pWorldModel) {
        // override in subclasses
    }

    public String getImpulseExpression() {
        if (this.preference > 0) return "Love";
        return "Hate";
    }

    public float getIntensity() {
        return super.getIntensity() * Math.abs(this.preference);
    }

    // SP
    public float getSignedIntensity() {
        return super.getIntensity() * this.preference;
    }

    protected StringBuffer valuesString() {
        return super.valuesString().append(" preference: " + this.preference);
    }

}
