001package com.box.sdk;
002
003import com.box.sdk.internal.utils.JsonUtils;
004import com.eclipsesource.json.JsonObject;
005import com.eclipsesource.json.JsonValue;
006
007/** Represents an AI Agent used for extraction. */
008@BoxResourceType("ai_agent_extract_structured")
009public class BoxAIAgentExtractStructured extends BoxAIAgent {
010
011  /** The type of the AI Ask agent. */
012  public static final String TYPE = "ai_agent_extract_structured";
013
014  /** AI agent tool used to handle basic text. */
015  private BoxAIAgentAskBasicText basicText;
016  /** AI agent tool used to handle longer text. */
017  private BoxAIAgentAskLongText longText;
018
019  /**
020   * Constructs an AI agent with default settings.
021   *
022   * @param basicText AI agent tool used to handle basic text.
023   * @param longText AI agent tool used to handle longer text.
024   */
025  public BoxAIAgentExtractStructured(
026      BoxAIAgentAskBasicText basicText, BoxAIAgentAskLongText longText) {
027    super(TYPE);
028    this.basicText = basicText;
029    this.longText = longText;
030  }
031
032  /**
033   * Constructs an AI agent with default settings.
034   *
035   * @param jsonObject JSON object representing the AI agent.
036   */
037  public BoxAIAgentExtractStructured(JsonObject jsonObject) {
038    super(jsonObject);
039  }
040
041  /**
042   * Gets the AI agent tool used to handle basic text.
043   *
044   * @return The AI agent tool used to handle basic text.
045   */
046  public BoxAIAgentAskBasicText getBasicText() {
047    return basicText;
048  }
049
050  /**
051   * Sets the AI agent tool used to handle basic text.
052   *
053   * @param basicText The AI agent tool used to handle basic text.
054   */
055  public void setBasicText(BoxAIAgentAskBasicText basicText) {
056    this.basicText = basicText;
057  }
058
059  /**
060   * Gets the AI agent tool used to handle longer text.
061   *
062   * @return The AI agent tool used to handle longer text.
063   */
064  public BoxAIAgentAskLongText getLongText() {
065    return longText;
066  }
067
068  /**
069   * Sets the AI agent tool used to handle longer text.
070   *
071   * @param longText The AI agent tool used to handle longer text.
072   */
073  public void setLongText(BoxAIAgentAskLongText longText) {
074    this.longText = longText;
075  }
076
077  @Override
078  void parseJSONMember(JsonObject.Member member) {
079    super.parseJSONMember(member);
080    String memberName = member.getName();
081    JsonValue memberValue = member.getValue();
082    try {
083      switch (memberName) {
084        case "basic_text":
085          this.basicText = new BoxAIAgentAskBasicText(memberValue.asObject());
086          break;
087        case "long_text":
088          this.longText = new BoxAIAgentAskLongText(memberValue.asObject());
089          break;
090        default:
091          break;
092      }
093    } catch (Exception e) {
094      throw new BoxAPIException("Could not parse JSON response.", e);
095    }
096  }
097
098  @Override
099  public JsonObject getJSONObject() {
100    JsonObject jsonObject = new JsonObject();
101    JsonUtils.addIfNotNull(jsonObject, "type", this.getType());
102    if (this.basicText != null) {
103      jsonObject.add("basic_text", this.basicText.getJSONObject());
104    }
105    if (this.longText != null) {
106      jsonObject.add("long_text", this.longText.getJSONObject());
107    }
108    return jsonObject;
109  }
110}