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")
009public class BoxAIAgentExtract extends BoxAIAgent {
010
011  /** The type of the AI Ask agent. */
012  public static final String TYPE = "ai_agent_extract";
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 BoxAIAgentExtract(BoxAIAgentAskBasicText basicText, BoxAIAgentAskLongText longText) {
026    super(TYPE);
027    this.basicText = basicText;
028    this.longText = longText;
029  }
030
031  /**
032   * Constructs an AI agent with default settings.
033   *
034   * @param jsonObject JSON object representing the AI agent.
035   */
036  public BoxAIAgentExtract(JsonObject jsonObject) {
037    super(jsonObject);
038  }
039
040  /**
041   * Gets the AI agent tool used to handle basic text.
042   *
043   * @return The AI agent tool used to handle basic text.
044   */
045  public BoxAIAgentAskBasicText getBasicText() {
046    return basicText;
047  }
048
049  /**
050   * Sets the AI agent tool used to handle basic text.
051   *
052   * @param basicText The AI agent tool used to handle basic text.
053   */
054  public void setBasicText(BoxAIAgentAskBasicText basicText) {
055    this.basicText = basicText;
056  }
057
058  /**
059   * Gets the AI agent tool used to handle longer text.
060   *
061   * @return The AI agent tool used to handle longer text.
062   */
063  public BoxAIAgentAskLongText getLongText() {
064    return longText;
065  }
066
067  /**
068   * Sets the AI agent tool used to handle longer text.
069   *
070   * @param longText The AI agent tool used to handle longer text.
071   */
072  public void setLongText(BoxAIAgentAskLongText longText) {
073    this.longText = longText;
074  }
075
076  @Override
077  void parseJSONMember(JsonObject.Member member) {
078    super.parseJSONMember(member);
079    String memberName = member.getName();
080    JsonValue memberValue = member.getValue();
081    try {
082      switch (memberName) {
083        case "basic_text":
084          this.basicText = new BoxAIAgentAskBasicText(memberValue.asObject());
085          break;
086        case "long_text":
087          this.longText = new BoxAIAgentAskLongText(memberValue.asObject());
088          break;
089        default:
090          break;
091      }
092    } catch (Exception e) {
093      throw new BoxAPIException("Could not parse JSON response.", e);
094    }
095  }
096
097  @Override
098  public JsonObject getJSONObject() {
099    JsonObject jsonObject = new JsonObject();
100    JsonUtils.addIfNotNull(jsonObject, "type", this.getType());
101    if (this.basicText != null) {
102      jsonObject.add("basic_text", this.basicText.getJSONObject());
103    }
104    if (this.longText != null) {
105      jsonObject.add("long_text", this.longText.getJSONObject());
106    }
107    return jsonObject;
108  }
109}