

package com.conversationkit.nlp;

import com.conversationkit.model.IConversationIntent;
import com.google.cloud.dialogflow.v2beta1.QueryResult;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author pdtyreus
 */
public class DialogFlowIntent implements IConversationIntent {

    private final QueryResult queryResult;

    public QueryResult getQueryResult() {
        return queryResult;
    }

    public DialogFlowIntent(QueryResult result) {
        this.queryResult = result;
    }

    @Override
    public String getIntentId() {
        //TODO - should this be Action name?
        return this.queryResult.getIntent().getDisplayName();
    }

    @Override
    public Map<String, Object> getSlots() {
        Struct params = this.queryResult.getParameters();
        Map<String, Value> paramMap = params.getFieldsMap();
        Map<String, Object> map = new HashMap();
        for (Map.Entry<String, Value> entry : paramMap.entrySet()) {
            map.put(entry.getKey(), entry.getValue());
        }
        return map;
    }

    @Override
    public boolean getAllRequiredSlotsFilled() {
        return this.queryResult.getAllRequiredParamsPresent();
    }

}
