001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004import com.eclipsesource.json.JsonValue;
005
006public abstract class BoxAIAgent extends BoxJSONObject {
007    /**
008     * The type of the AI agent.
009     * Value can be "ai_agent_ask" or "ai_agent_text_gen", "ai_agent_extract", "ai_agent_extract_structured".
010     */
011    private String type;
012
013    /**
014     * Constructs an AI agent with default settings.
015     * @param type The type of the AI agent.
016     *            Value can be "ai_agent_ask", "ai_agent_text_gen", "ai_agent_extract", "ai_agent_extract_structured".
017     */
018    public BoxAIAgent(String type) {
019        super();
020        this.type = type;
021    }
022
023    /**
024     * Constructs an AI agent with default settings.
025     * @param jsonObject JSON object representing the AI agent.
026     */
027    public BoxAIAgent(JsonObject jsonObject) {
028        super(jsonObject);
029    }
030
031    /**
032     * Constructs an AI agent with default settings.
033     * @param jsonObject JSON object representing the AI agent.
034     */
035    public static BoxAIAgent parse(JsonObject jsonObject) {
036        String type = jsonObject.get("type").asString();
037        if (type.equals(BoxAIAgentAsk.TYPE)) {
038            return new BoxAIAgentAsk(jsonObject);
039        } else if (type.equals(BoxAIAgentTextGen.TYPE)) {
040            return new BoxAIAgentTextGen(jsonObject);
041        } else if (type.equals(BoxAIAgentExtract.TYPE)) {
042            return new BoxAIAgentExtract(jsonObject);
043        } else if (type.equals(BoxAIAgentExtractStructured.TYPE)) {
044            return new BoxAIAgentExtractStructured(jsonObject);
045        } else {
046            throw new IllegalArgumentException("Invalid AI agent type: " + type);
047        }
048    }
049
050    /**
051     * Gets the type of the AI agent.
052     * @return The type of the AI agent.
053     */
054    public String getType() {
055        return type;
056    }
057
058    /**
059     * Sets the type of the AI agent.
060     * @param type The type of the AI agent.
061     */
062    public void setType(String type) {
063        this.type = type;
064    }
065
066    @Override
067    void parseJSONMember(JsonObject.Member member) {
068        super.parseJSONMember(member);
069        String memberName = member.getName();
070        JsonValue value = member.getValue();
071        if (memberName.equals("type")) {
072            this.type = value.asString();
073        }
074    }
075
076    public JsonObject getJSONObject() {
077        JsonObject jsonObject = new JsonObject();
078        jsonObject.add("type", this.type);
079        return jsonObject;
080    }
081
082    /**
083     * The type of the AI agent for asking questions.
084     */
085    public enum Mode {
086        /**
087         * The type of AI agent used to handle queries.
088         */
089        ASK("ask"),
090        /**
091         * The type of AI agent used for generating text.
092         */
093        TEXT_GEN("text_gen"),
094        /**
095         * The type of AI agent used for extracting metadata freeform.
096         */
097        EXTRACT("extract"),
098        /**
099         * The type of AI agent used for extracting metadata structured.
100         */
101        EXTRACT_STRUCTURED("extract_structured");
102
103
104        private final String value;
105
106        Mode(String value) {
107            this.value = value;
108        }
109
110        static BoxAIAgent.Mode fromJSONValue(String value) {
111            if (value.equals("ask")) {
112                return ASK;
113            } else if (value.equals("text_gen")) {
114                return TEXT_GEN;
115            } else if (value.equals("extract")) {
116                return EXTRACT;
117            } else if (value.equals("extract_structured")) {
118                return EXTRACT_STRUCTURED;
119            } else {
120                throw new IllegalArgumentException("Invalid AI agent mode: " + value);
121            }
122        }
123
124        String toJSONValue() {
125            return this.value;
126        }
127
128        @Override
129        public String toString() {
130            return this.value;
131        }
132    }
133}