001package com.box.sdk; 002 003import com.eclipsesource.json.JsonObject; 004import com.eclipsesource.json.JsonValue; 005import java.text.ParseException; 006import java.util.Date; 007 008/** AI response to a user request. */ 009public class BoxAIResponse extends BoxJSONObject { 010 private String answer; 011 private String completionReason; 012 private Date createdAt; 013 014 /** Constructs a BoxAIResponse object. */ 015 public BoxAIResponse(String answer, String completionReason, Date createdAt) { 016 super(); 017 this.answer = answer; 018 this.completionReason = completionReason; 019 this.createdAt = createdAt; 020 } 021 022 /** 023 * Constructs a BoxAIResponse from a JSON string. 024 * 025 * @param json the JSON encoded upload email. 026 */ 027 public BoxAIResponse(String json) { 028 super(json); 029 } 030 031 /** 032 * Constructs an BoxAIResponse object using an already parsed JSON object. 033 * 034 * @param jsonObject the parsed JSON object. 035 */ 036 BoxAIResponse(JsonObject jsonObject) { 037 super(jsonObject); 038 } 039 040 /** 041 * Gets the answer of the AI. 042 * 043 * @return the answer of the AI. 044 */ 045 public String getAnswer() { 046 return answer; 047 } 048 049 /** 050 * Gets reason the response finishes. 051 * 052 * @return the reason the response finishes. 053 */ 054 public String getCompletionReason() { 055 return completionReason; 056 } 057 058 /** 059 * Gets the ISO date formatted timestamp of when the answer to the prompt was created. 060 * 061 * @return The ISO date formatted timestamp of when the answer to the prompt was created. 062 */ 063 public Date getCreatedAt() { 064 return createdAt; 065 } 066 067 /** {@inheritDoc} */ 068 @Override 069 void parseJSONMember(JsonObject.Member member) { 070 JsonValue value = member.getValue(); 071 String memberName = member.getName(); 072 try { 073 if (memberName.equals("answer")) { 074 this.answer = value.asString(); 075 } else if (memberName.equals("completion_reason")) { 076 this.completionReason = value.asString(); 077 } else if (memberName.equals("created_at")) { 078 this.createdAt = BoxDateFormat.parse(value.asString()); 079 } 080 } catch (ParseException e) { 081 assert false : "A ParseException indicates a bug in the SDK."; 082 } 083 } 084}