001/*
002 * Copyright (c) 2026, Oracle and/or its affiliates.
003 *
004 * Licensed under the Universal Permissive License Version 1.0 as shown at
005 * https://oss.oracle.com/licenses/upl/
006 */
007package com.oracle.database.selectai;
008
009import com.oracle.database.selectai.model.ConversationAttributes;
010import com.oracle.database.selectai.model.ConversationPrompt;
011import com.oracle.database.selectai.model.SelectAIException;
012
013import java.util.List;
014
015/**
016 * Contract for Select AI conversation lifecycle and metadata management.
017 * <p>
018 * A conversation stores chat context so a later prompt can refer to earlier
019 * turns. The {@code Conversation} object manages the database conversation and its metadata,
020 * such as title, description, retention period, and context length.
021 * <p>
022 * A {@code Conversation} object can be configured for creation or
023 * database-backed. A configured conversation has attributes in memory, but it
024 * does not have a database conversation ID until {@link #create()} succeeds. A
025 * database-backed conversation is opened from the database, listed from
026 * metadata, or successfully created through this SDK.
027 * <p>
028 * Metadata getters can return configured values before creation. Operations
029 * that execute against an existing database conversation, such as drop,
030 * metadata update, prompt listing, and prompt deletion, require a
031 * database-backed conversation. The SDK rejects those operations with
032 * {@link IllegalStateException} when the object is not bound to a conversation
033 * ID or is configured for creation but has not been created yet.
034 *
035 * @see <a href="https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/dbms-cloud-ai-package.html">
036 *      DBMS_CLOUD_AI conversation reference</a>
037 */
038public interface Conversation {
039    /**
040     * Returns the database identifier for this conversation.
041     * <p>
042     * For a complete runnable sample source, see
043     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/GetConversationIdSample.html">
044     * GetConversationIdSample source</a>.
045     *
046     * @return conversation ID
047     */
048    String getConversationId();
049
050    /**
051     * Drops this conversation from the database.
052     * <p>
053     * For a complete runnable sample source, see
054     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/DropConversationSample.html">
055     * DropConversationSample source</a>.
056     *
057     * @param force when {@code true}, performs force drop if supported
058     * @return {@code true} when drop succeeds
059     * @throws IllegalStateException when this Conversation instance is not bound to a conversation ID
060     *         or is configured for creation but has not been created yet
061     * @throws SelectAIException when the database conversation cannot be dropped
062     */
063    boolean drop(boolean force) throws SelectAIException;
064
065    /**
066     * Creates the configured conversation in the database and returns its
067     * generated conversation identifier.
068     * <p>
069     * Call this after obtaining a conversation object from
070     * {@link SelectAI#conversation(ConversationAttributes)}.
071     * For a complete runnable sample source, see
072     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/CreateConversationSample.html">
073     * CreateConversationSample source</a>.
074     *
075     * @return conversation ID returned by {@code DBMS_CLOUD_AI.CREATE_CONVERSATION}
076     * @throws SelectAIException when the conversation cannot be created
077     */
078    String create() throws SelectAIException;
079
080    /**
081     * Returns conversation metadata.
082     * <p>
083     * For a configured conversation that has not been created yet, returns the
084     * attributes supplied by the caller. For a conversation bound to a
085     * conversation ID, refreshes metadata from the database before returning
086     * attributes.
087     * For a complete runnable sample source, see
088     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/GetConversationAttributesSample.html">
089     * GetConversationAttributesSample source</a>.
090     *
091     * @return conversation attributes
092     * @throws SelectAIException when bound conversation metadata cannot be fetched
093     */
094    ConversationAttributes getConversationAttributes() throws SelectAIException;
095
096    /**
097     * Updates conversation metadata such as title, description, retention, or
098     * context length.
099     * <p>
100     * For a complete runnable sample source, see
101     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/SetConversationAttributesSample.html">
102     * SetConversationAttributesSample source</a>.
103     *
104     * @param conversationAttributes attributes to set
105     * @return {@code true} when update succeeds
106     * @throws IllegalStateException when this Conversation instance is not bound to a conversation ID
107     *         or is configured for creation but has not been created yet
108     * @throws SelectAIException when update fails
109     */
110    boolean setAttributes(ConversationAttributes conversationAttributes) throws SelectAIException;
111
112    /**
113     * Lists prompts recorded for this conversation.
114     * <p>
115     * For a complete runnable sample source, see
116     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/ListConversationPromptsSample.html">
117     * ListConversationPromptsSample source</a>.
118     *
119     * @return prompt rows for this conversation ordered by creation time
120     * @throws IllegalStateException when this Conversation instance is not bound to a conversation ID
121     *         or is configured for creation but has not been created yet
122     * @throws SelectAIException when the prompt metadata cannot be fetched
123     */
124    List<ConversationPrompt> listPrompts() throws SelectAIException;
125
126    /**
127     * Deletes a conversation prompt.
128     * <p>
129     * For a complete runnable sample source, see
130     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/DeleteConversationPromptSample.html">
131     * DeleteConversationPromptSample source</a>.
132     *
133     * @param conversationPromptId conversation prompt identifier
134     * @return {@code true} when delete succeeds
135     * @throws IllegalStateException when this Conversation instance is not bound to a conversation ID
136     *         or is configured for creation but has not been created yet
137     * @throws SelectAIException when the prompt cannot be deleted
138     */
139    boolean deletePrompt(String conversationPromptId) throws SelectAIException;
140
141    /**
142     * Deletes a conversation prompt.
143     * <p>
144     * For a complete runnable sample source, see
145     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/conversation/DeleteConversationPromptSample.html">
146     * DeleteConversationPromptSample source</a>.
147     *
148     * @param conversationPromptId conversation prompt identifier
149     * @param force when {@code true}, performs force delete if supported
150     * @return {@code true} when delete succeeds
151     * @throws IllegalStateException when this Conversation instance is not bound to a conversation ID
152     *         or is configured for creation but has not been created yet
153     * @throws SelectAIException when the prompt cannot be deleted
154     */
155    boolean deletePrompt(String conversationPromptId, boolean force) throws SelectAIException;
156}