package com.xunhong.erp.turbo.dify;

import com.alibaba.fastjson2.JSONObject;
import org.apache.http.client.methods.CloseableHttpResponse;

public class WorkflowClient extends DifyClient {
	/**
	 * Constructs a new CompletionClient with the provided API key.
	 *
	 * @param apiKey The API key to use for authentication.
	 */
	public WorkflowClient(String apiKey) {
		super(apiKey);
	}

	/**
	 * Constructs a new CompletionClient with the provided API key and base URL.
	 *
	 * @param apiKey  The API key to use for authentication.
	 * @param baseUrl The base URL of the Dify API.
	 */
	public WorkflowClient(String apiKey, String baseUrl) {
		super(apiKey, baseUrl);
	}

	public CloseableHttpResponse createWorkflowRun(String inputs, String user, boolean stream) throws DifyClientException {
		JSONObject json = new JSONObject();
		json.put("inputs", JSONObject.parseObject(inputs));
		json.put("user", user);
		json.put("response_mode", stream ? "streaming" : "blocking");

		return sendRequest(WORKFLOW_RUN, null, createJsonPayload(json));
	}
}
